### Running Deno SQLite3 Example Source: https://github.com/denodrivers/sqlite3/blob/main/README.md Shows the command to run a Deno script that uses the SQLite3 module. Requires network and file system permissions, typically granted with the --allow-all flag. ```shell deno run -A ``` -------------------------------- ### Initialize and Query SQLite Database Source: https://github.com/denodrivers/sqlite3/blob/main/README.md Demonstrates how to import the Database class, create a new SQLite database file, execute a query to get the SQLite version, and close the database connection. ```typescript import { Database } from "jsr:@db/sqlite@0.13"; const db = new Database("test.db"); const [version] = db.prepare("select sqlite_version()").value<[string]>()!; console.log(version); db.close(); ``` -------------------------------- ### Retrieving the First Row as an Object with get() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `get()` method executes a prepared statement and returns the first row as an object, or undefined if no rows are found. ```APIDOC ## Retrieving the First Row as an Object with get() ### Description Executes a prepared statement and returns the first row as an object, or undefined if no rows are found. ### Method `stmt.get(...params: unknown[]): T | undefined` ### Parameters - `...params` (unknown[]): Parameters to bind to the statement. ### Request Example ```ts interface Foo { bar: string; baz: number; } const row = stmt.get(...params); ``` ### Response - `row` (T | undefined): An object representing the first row, or undefined. ``` -------------------------------- ### Retrieve the First Row as an Object from a Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `get()` method on a prepared `Statement` object to execute it and retrieve the first resulting row as an object. Supports generic type parameters for specifying the return object structure. ```typescript const row = stmt.get(...params); ``` ```typescript const row = stmt.get(...params); // row is Foo | undefined ``` -------------------------------- ### Accessing Statement Status Counters Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Illustrates how to retrieve and optionally reset statement status counters like 'run', 'vmStep', and 'memused'. Use the reset option to get the current value and clear it for subsequent reads. ```ts const stmt = db.prepare("SELECT text FROM test ORDER BY text"); stmt.values(); const runs = stmt.statusRun(); // > 0 const vmSteps = stmt.statusVmStep(true); // read and reset const vmStepsAfterReset = stmt.statusVmStep(); // 0 const mem = stmt.statusMemused(); // approximate bytes used by statement ``` -------------------------------- ### Opening a Database Connection Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Demonstrates how to open a new SQLite database connection using the Database constructor with various options. ```APIDOC ## Opening Database To open a new Database connection, construct the `Database` class with the path to the database file. If the file does not exist, it will be created unless you pass `create: false` in the options. ### Options - `create: boolean` - Whether to create the database file if it does not exist. Defaults to `true`. - `readonly: boolean` - Whether to open the database in read-only mode. Defaults to `false`. - `memory: boolean` - Whether to open the database in memory. Defaults to `false`. - `int64: boolean` - Whether to support BigInt columns. False by default, which means integers larger than 32 bit will be inaccurate. Causes mixed values to be returned like `number | bigint`. - `flags: number` - Raw flags to pass to the C API. Normally you don't need this. Passing this ignores all other options. - `unsafeConcurrency: boolean` - Enable optimizations that will affect syncronization with other clients. This can largerly improve performance for cases where you only have one client. - `enableLoadExtension: boolean` - Enables the loading of SQLite extensions from a dynamic library, this needs to be set to true for the method `loadExtension` to work. Defaults to `false`. - `parseJson: boolean` - Enables parsing JSON. True by default. ### Usage ```ts // Open using default options const db = new Database("test.db"); // Open using URL path (relative to current file/module, not CWD) const db = new Database(new URL("./test.db", import.meta.url)); // Open in memory const db = new Database(":memory:"); // Open in read-only mode const db = new Database("test.db", { readonly: true }); // Open existing database, error if it doesn't exist const db = new Database("test.db", { create: false }); ``` ``` -------------------------------- ### Build SQLite3 from Source Source: https://github.com/denodrivers/sqlite3/blob/main/README.md Command to build the SQLite3 module from its source code. Ensure submodules are initialized before running. ```shell deno task build ``` -------------------------------- ### Binding Parameters Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Demonstrates how to bind parameters by name and position to SQL queries using the SQLite3 driver. ```APIDOC ## Binding Parameters Parameters can be bound both by name and positiion. To bind by name, just pass an object mapping the parameter name to the value. To bind by position, pass the values as rest parameters. SQLite supports `:`, `@` and `$` as prefix for named bind parameters. If you don't have any in the Object's keys, the `:` prefix will be used by default. Bind parameters can be passed to `Database#exec` after SQL parameter, or to `Statement`'s `bind`/`all`/`values`/`run` function. ```ts // Bind by name db.exec("INSERT INTO foo VALUES (:bar)", { bar: "baz" }); // In prepared statements const stmt = db.prepare("INSERT INTO foo VALUES (:bar)"); stmt.run({ bar: "baz" }); // Bind by position db.exec("INSERT INTO foo VALUES (?)", "baz"); // In prepared statements const stmt = db.prepare("INSERT INTO foo VALUES (?, ?)"); stmt.run("baz", "foo"); ``` ``` -------------------------------- ### Loading SQLite Extensions Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Explains how to enable and use the `loadExtension` method and SQL function to load SQLite extensions. ```APIDOC ## Loading extensions Loading SQLite3 extensions is enabled through the `enableLoadExtension` property and config option. For security reasons it is disabled by default. If enabled it is used with the `loadExtension` method on the database, it will attempt to load the specified file as specified by the [SQLite documentation](https://www.sqlite.org/c3ref/load_extension.html). Optionally a second argument can be passed to the method specifying the entrypoint name. ```ts const db = new Database("test.db", { enableLoadExtension: true }); db.loadExtension("mod_spatialite"); ``` It is also possible to load an extension directly from SQL using the `load_extension` functions as specified by the [SQLite documentation](https://www.sqlite.org/lang_corefunc.html#load_extension). ```ts db.exec("SELECT load_extension('mod_spatialite')"); ``` ``` -------------------------------- ### Execute SQL with Parameters using .sql Tagged Template Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `.sql` tagged template for safely executing SQL with parameters. It binds parameters and returns all rows using `.all()`. This is a convenient alternative to manual parameter binding. ```typescript const minimum = 20; const results = db.sql` SELECT id, name, age FROM students WHERE age > ${minimum}`; console.log(results); // [ [ 2, "Brian", 30 ] ] ``` -------------------------------- ### Executing a Prepared Statement with run() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `run()` method executes a prepared statement and returns the number of changes made. ```APIDOC ## Executing Statement with run() ### Description Executes a prepared statement and returns the number of changes made. ### Method `stmt.run(...params: unknown[]): number` ### Parameters - `...params` (unknown[]): Parameters to bind to the statement. ### Request Example ```ts const changes = stmt.run(...params); ``` ### Response - `changes` (number): The number of changes made by the statement. ``` -------------------------------- ### Creating Prepared Statements with prepare() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `prepare()` method creates a `Statement` object from an SQL string, which can then be used to execute the statement, bind parameters, and retrieve results. ```APIDOC ## Creating Prepared Statements with prepare() ### Description Prepares an SQL statement for execution, returning a `Statement` object. ### Method `db.prepare(sql: string): Statement` ### Parameters - `sql` (string): The SQL string to prepare. ### Request Example ```ts const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?"); // or with a using statement { using stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?"); // use stmt } ``` ### Response - `stmt` (Statement): A prepared statement object. ``` -------------------------------- ### Binding Parameters in SQLite3 Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Demonstrates binding parameters by name and position for both direct execution and prepared statements. SQLite supports ':', '@', and '$' as prefixes for named parameters. ```ts // Bind by name db.exec("INSERT INTO foo VALUES (:bar)", { bar: "baz" }); // In prepared statements const stmt = db.prepare("INSERT INTO foo VALUES (:bar)"); stmt.run({ bar: "baz" }); // Bind by position db.exec("INSERT INTO foo VALUES (?)", "baz"); // In prepared statements const stmt = db.prepare("INSERT INTO foo VALUES (?, ?)"); stmt.run("baz", "foo"); ``` -------------------------------- ### Load SQLite Extension via Method Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Enable loading of SQLite extensions by setting `enableLoadExtension` to true in the Database constructor options. Then, use the `loadExtension` method to load a specified extension file. ```typescript const db = new Database("test.db", { enableLoadExtension: true }); db.loadExtension("mod_spatialite"); ``` -------------------------------- ### Open SQLite Database Connection Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Construct the Database class with the path to the database file. The file will be created if it doesn't exist by default. Options can be provided to customize behavior like read-only mode or in-memory databases. ```typescript const db = new Database("test.db"); ``` ```typescript const db = new Database(new URL("./test.db", import.meta.url)); ``` ```typescript const db = new Database(":memory:"); ``` ```typescript const db = new Database("test.db", { readonly: true }); ``` ```typescript const db = new Database("test.db", { create: false }); ``` -------------------------------- ### Run Benchmarks with Local SQLite Library Source: https://github.com/denodrivers/sqlite3/blob/main/README.md Executes the benchmarks for the Deno SQLite3 module, specifically using a locally compiled SQLite library. This is achieved by setting the DENO_SQLITE_LOCAL environment variable. ```shell DENO_SQLITE_LOCAL=1 deno task bench ``` -------------------------------- ### Prepare a SQL Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use `prepare()` to create a `Statement` object for reusable execution. The statement can be used within a block for automatic disposal or managed manually. ```typescript const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?"); // or with a using statement { using stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?"); // use stmt } // automatically disposed ``` -------------------------------- ### Execute a Prepared Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `run()` method on a prepared `Statement` object to execute it. It returns the number of changes made by the statement. ```typescript const changes = stmt.run(...params); ``` -------------------------------- ### Load SQLite Extension via SQL Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md It is also possible to load an extension directly from SQL using the `load_extension` function. This requires the database connection to be open and the extension to be accessible. ```sql db.exec("SELECT load_extension('mod_spatialite')"); ``` -------------------------------- ### Retrieving All Rows with all() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `all()` method executes a prepared statement and returns all rows as an array of objects. ```APIDOC ## Retrieving All Rows with all() ### Description Executes a prepared statement and returns all rows as an array of objects. ### Method `stmt.all(...params: unknown[]): T[]` ### Parameters - `...params` (unknown[]): Parameters to bind to the statement. ### Request Example ```ts interface Foo { bar: string; baz: number; } const rows = stmt.all(...params); ``` ### Response - `rows` (Array): An array of objects representing the rows returned. ``` -------------------------------- ### JavaScript to SQLite Type Mapping Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Illustrates the mapping between JavaScript data types and SQLite data types for both input and output. ```APIDOC ## JavaScript to SQLite type mapping: | JavaScript type | SQLite type | | ----------------------- | --------------------------- | | `null` | `NULL` | | `undefined` | `NULL` | | `number` | `INTEGER`/`FLOAT` | | `bigint` | `INTEGER` | | `string` | `TEXT` | | `boolean` | `INTEGER` | | `Date` | `TEXT` (ISO) | | `Uint8Array` | `BLOB` | | JSON-serializable value | `TEXT` (`JSON.stringify()`) When retrieving rows, the types are mapped back to JavaScript types: | SQLite type | JavaScript type | | ------------------------ | ------------------------- | | `NULL` | `null` | | `INTEGER` | `number`/`bigint` | | `FLOAT` | `number` | | `TEXT` | `string` | | `TEXT` with JSON subtype | `object` (`JSON.parse()`) | | `BLOB` | `Uint8Array` | Note 1: The `int64` option allows you to return `BigInt` for integers bigger than max safe integer in JavaScript. It is disabled by default, and precision may not be accurate for bigger numbers. When enabled, the library can return both `number | bigint`, but when disabled (default), it will only return `number`. In the former case, `bigint` is returned ONLY if its too big to fit in a JavaScript Number. Note 2: We only support `Uint8Array` for the `BLOB` type as V8 Fast API will optimize for it instead of other arrays like `Uint16Array`. And it is also to stay consistent: we only support passing `Uint8Array` and we consistently return `Uint8Array` when we return a `BLOB` to JS. It is easy to support passing all typed arrays with good performance, but then at the time we have to retreive again we don't know what the original typed array type was, as the only type into in the column is that it is a `BLOB`. You can easily convert between other typed arrays and `Uint8Array` like this: ```ts const f32 = new Float32Array(1); const u8 = new Uint8Array(f32.buffer); // no copy, can pass this const u8FromSqlite = new Uint8Array(4); const f32FromSqlite = new Float32Array(u8FromSqlite.buffer); // safely convert back when retrieved from sqlite, no copy ``` Note 3: The `parseJson` option allows you to disable JSON parsing which is enabled by default. ``` -------------------------------- ### Executing SQL with Tagged Template Literal Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `.sql` tagged template literal provides a safe way to execute SQL queries with parameters, returning all rows using `.all()`. ```APIDOC ## Executing SQL with Tagged Template Literal ### Description Safely executes SQL queries with bound parameters using the `.sql` tagged template literal and returns all rows. ### Method `db.sql` tagged template literal ### Parameters - Template literal string with embedded expressions for parameters. ### Request Example ```ts const minimum = 20; const results = db.sql` SELECT id, name, age FROM students WHERE age > ${minimum} `; console.log(results); // [ [ 2, "Brian", 30 ] ] ``` ### Response - `results` (Array>): An array of rows, where each row is an array of values. ``` -------------------------------- ### Execute a Transaction Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use `transaction()` to define and run a transaction. It automatically handles `BEGIN`, `COMMIT`, and `ROLLBACK`. Nested transactions use `SAVEPOINT`/`RELEASE`/`ROLLBACK TO`. ```typescript const stmt = db.prepare("INSERT INTO foo VALUES (?)"); const runTransaction = db.transaction((data: SomeData[]) => { for (const item of data) { stmt.run(item.value); } }); runTransaction([ { value: "bar" }, { value: "baz" }, ]); ``` ```typescript // Run with BEGIN DEFERRED runTransaction.deferred([ { value: "bar" }, { value: "baz" }, ]); ``` -------------------------------- ### Handling JSON with SQLite Functions Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Demonstrates how the driver handles SQLite's built-in JSON functions, automatically parsing JSON values into JavaScript objects or arrays. ```APIDOC ## SQLite functions that return JSON ### Description When using SQLite's built-in JSON functions, the `sqlite3` driver automatically parses JSON values into JavaScript objects or arrays. ### Request Example ```ts const [list] = db .prepare("SELECT json_array(1, 2, 3) as list") .value<[number[]]>()!; // list = [ 1, 2, 3 ] const [object] = db .prepare("SELECT json_object('name', 'Peter') as object") .value<[{ name: string }]>( )!; // object = { name: "Peter" } ``` ### Usage Use the builtin `json()` SQL function to convert text values into JSON. ``` -------------------------------- ### Retrieving the First Row as an Array with value() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `value()` method executes a prepared statement and returns the first row as an array, or undefined if no rows are found. ```APIDOC ## Retrieving the First Row as an Array with value() ### Description Executes a prepared statement and returns the first row as an array, or undefined if no rows are found. ### Method `stmt.value(...params: unknown[]): T[] | undefined` ### Parameters - `...params` (unknown[]): Parameters to bind to the statement. ### Request Example ```ts const row = stmt.value<[string, number]>(...params); ``` ### Response - `row` (Array | undefined): An array representing the first row, or undefined. ``` -------------------------------- ### Statement Properties Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Provides details about the properties available on a prepared `Statement` object. ```APIDOC ## Properties of `Statement` ### Description Details the properties available on a prepared `Statement` object. ### Properties - `db: Database` - The database the statement belongs to. - `expandedSql: string` - The SQL string with all bound parameters expanded. - `sql: string` - The SQL string used to prepare the statement. - `readonly: boolean` - Whether the statement is read-only. - `bindParameterCount: number` - The number of parameters the statement expects. ### Statement Level Options - `enableInt64`, `enableParseJson`, `disableInt64`, `disableParseJson`, `defaultInt64`, `defaultParseJson`: Options to override behavior for a specific statement. ``` -------------------------------- ### Executing SQL Statements with exec() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `exec()` method executes all statements in a given SQL string and returns the number of changes made by the last statement. It's suitable for DDL and pragma statements that do not return data. ```APIDOC ## Executing SQL with exec() ### Description Executes all SQL statements in the provided string and returns the number of changes made by the last statement. Useful for DDL and pragma statements. ### Method `db.exec(sql: string, ...params: unknown[]): number` ### Parameters - `sql` (string): The SQL string to execute. - `...params` (unknown[]): Optional parameters to bind to the statement (only supported for a single statement). ### Request Example ```ts const changes = db.exec( "CREATE TABLE foo (bar TEXT); INSERT INTO foo VALUES ('baz');", ); console.log(changes); // 1 db.exec("pragma journal_mode = WAL"); ``` ### Response - `changes` (number): The number of changes made by the last statement. ``` -------------------------------- ### Closing a Database Connection Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Provides instructions on how to properly close a database connection to free up resources. ```APIDOC ## Closing Database To close the database connection, call the `close()` method. This will close the database connection and free all resources associated with it. Calling it more than once will be a no-op. ```ts db.close(); ``` ``` -------------------------------- ### Retrieving All Rows as Arrays with values() Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md The `values()` method executes a prepared statement and returns all rows as an array of arrays. ```APIDOC ## Retrieving All Rows as Arrays with values() ### Description Executes a prepared statement and returns all rows as an array of arrays. ### Method `stmt.values(...params: unknown[]): T[][]` ### Parameters - `...params` (unknown[]): Parameters to bind to the statement. ### Request Example ```ts const rows = stmt.values<[string, number]>(...params); ``` ### Response - `rows` (Array>): An array of arrays representing the rows returned. ``` -------------------------------- ### Automatically Free Prepared Statements with `using` Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `using` statement to automatically free a statement when its scope ends. ```typescript { using stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?"); stmt.run("bar", "baz"); } ``` -------------------------------- ### Execute Raw SQL Statements Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use `exec()` to run DDL statements like CREATE, DROP, ALTER, and pragmas that do not return data. It returns the number of changes made by the last statement. Note: When parameters are passed to `exec()`, it supports only one statement at a time. ```typescript const changes = db.exec( "CREATE TABLE foo (bar TEXT); INSERT INTO foo VALUES ('baz');", ); console.log(changes); // 1 // Executing pragma statements db.exec("pragma journal_mode = WAL"); db.exec("pragma synchronous = normal"); db.exec("pragma temp_store = memory"); ``` -------------------------------- ### Retrieve the First Row as an Array from a Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `value()` method on a prepared `Statement` object to execute it and retrieve the first resulting row as an array. Supports generic type parameters for specifying the return array structure. ```typescript const row = stmt.value(...params); ``` ```typescript const row = stmt.value<[string, number]>(...params); // row is [string, number] | undefined ``` -------------------------------- ### Set Fixed Parameters for a Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use `bind()` to set fixed parameters for a statement. This method can only be called once and is an optimization to avoid rebinding parameters on each execution. ```typescript const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?"); stmt.bind("bar", "baz"); ``` -------------------------------- ### Retrieve All Rows from a Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `all()` method on a prepared `Statement` object to execute it and retrieve all resulting rows as an array of objects. Supports generic type parameters for specifying the return object structure. ```typescript const rows = stmt.all(...params); ``` ```typescript interface Foo { bar: string; baz: number; } const rows = stmt.all(...params); // rows is Foo[] ``` -------------------------------- ### Typed Array Conversion for BLOBs Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Shows how to convert between JavaScript typed arrays and Uint8Array for BLOB data. This is useful for passing data to SQLite and safely converting it back upon retrieval. ```ts const f32 = new Float32Array(1); const u8 = new Uint8Array(f32.buffer); // no copy, can pass this const u8FromSqlite = new Uint8Array(4); const f32FromSqlite = new Float32Array(u8FromSqlite.buffer); // safely convert back when retrieved from sqlite, no copy ``` -------------------------------- ### Retrieve All Rows as Arrays from a Statement Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Use the `values()` method on a prepared `Statement` object to execute it and retrieve all resulting rows as an array of arrays. Supports generic type parameters for specifying the return array structure. ```typescript const rows = stmt.values(...params); ``` ```typescript const values = stmt.values<[string, number]>(...params); // values is [string, number][] ``` -------------------------------- ### Iterate Over Statement Rows Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Iterate directly over the statement object to fetch rows one by one, useful for large result sets. Ensure parameters are bound using `bind()` before iterating. ```typescript for (const row of stmt) { console.log(row); } ``` -------------------------------- ### Manually Free Prepared Statements Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Call `finalize()` to manually free a statement. Do not use the statement after calling this method. ```typescript stmt.finalize(); ``` -------------------------------- ### Statement Status Counters Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Provides methods to access and reset SQLite statement status counters. ```APIDOC ## Statement Status Counters Prepared statements expose SQLite `sqlite3_stmt_status()` values through helper methods: - `statusFullscanStep(reset?: boolean): number` - `statusSort(reset?: boolean): number` - `statusAutoindex(reset?: boolean): number` - `statusVmStep(reset?: boolean): number` - `statusReprepare(reset?: boolean): number` - `statusRun(reset?: boolean): number` - `statusFilterMiss(reset?: boolean): number` - `statusFilterHit(reset?: boolean): number` - `statusMemused(): number` Passing `true` to `reset` returns the current counter value and resets it to zero for future reads. ```ts const stmt = db.prepare("SELECT text FROM test ORDER BY text"); stmt.values(); const runs = stmt.statusRun(); // > 0 const vmSteps = stmt.statusVmStep(true); // read and reset const vmStepsAfterReset = stmt.statusVmStep(); // 0 const mem = stmt.statusMemused(); // approximate bytes used by statement ``` ``` -------------------------------- ### Close SQLite Database Connection Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md Call the `close()` method on the Database object to close the connection and free associated resources. Calling `close()` more than once has no effect. ```typescript db.close(); ``` -------------------------------- ### Handle SQLite JSON Functions Source: https://github.com/denodrivers/sqlite3/blob/main/doc.md When using SQLite's built-in JSON functions, `sqlite3` automatically parses JSON text values into JavaScript objects or arrays. Use the `json()` SQL function to convert text values to JSON. ```typescript const [list] = db .prepare("SELECT json_array(1, 2, 3) as list") .value<[number[]]>()!; // list = [ 1, 2, 3 ] ``` ```typescript const [object] = db .prepare("SELECT json_object('name', 'Peter') as object") .value<[{ name: string }]>( )!; // object = { name: "Peter" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.