SQLite-JS Extension SQLite-JS is a powerful extension that brings JavaScript capabilities to SQLite. With this extension, you can create custom SQLite functions, aggregates, window functions, and collation sequences using JavaScript code, allowing for flexible and powerful data manipulation directly within your SQLite database. Table of Contents Installation Pre-built Binaries Download the appropriate pre-built binary for your platform from the official Releases page: Linux: x86 and ARM macOS: x86 and ARM Windows: x86 Android iOS Loading the Extension -- In SQLite CLI .load . / js -- In SQL SELECT load_extension( ' ./js ' ); Functions Overview SQLite-JS provides several ways to extend SQLite functionality with JavaScript: Function Type Description Scalar Functions Process individual rows and return a single value Aggregate Functions Process multiple rows and return a single aggregated result Window Functions Similar to aggregates but can access the full dataset Collation Sequences Define custom sort orders for text values JavaScript Evaluation Directly evaluate JavaScript code within SQLite Scalar Functions Scalar functions process one row at a time and return a single value. They are useful for data transformation, calculations, text manipulation, etc. Usage SELECT js_create_scalar( ' function_name ' , ' function_code ' ); Parameters function_name : The name of your custom function : The name of your custom function function_code: JavaScript code that defines your function. Must be in the form function(args) { /* your code here */ } Example -- Create a custom function to calculate age from birth date SELECT js_create_scalar( ' age ' , ' function(args) { const birthDate = new Date(args[0]); const today = new Date(); let age = today.getFullYear() - birthDate.getFullYear(); const m = today.getMonth() - birthDate.getMonth(); if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { age--; } return age; } ' ); -- Use the function SELECT name, age(birth_date) FR...
First seen: 2025-05-22 14:25
Last seen: 2025-05-23 13:29