{
  "type": "module",
  "source": "doc/api/sqlite.md",
  "modules": [
    {
      "textRaw": "SQLite",
      "name": "sqlite",
      "introduced_in": "v22.5.0",
      "meta": {
        "added": [
          "v22.5.0"
        ],
        "changes": []
      },
      "stability": 1,
      "stabilityText": ".1 - Active development. Enable this API with the [`--experimental-sqlite`][] CLI flag.",
      "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v22.6.0/lib/sqlite.js\">lib/sqlite.js</a></p>\n<p>The <code>node:sqlite</code> module facilitates working with SQLite databases.\nTo access it:</p>\n<pre><code class=\"language-mjs\">import sqlite from 'node:sqlite';\n</code></pre>\n<pre><code class=\"language-cjs\">const sqlite = require('node:sqlite');\n</code></pre>\n<p>This module is only available under the <code>node:</code> scheme. The following will not\nwork:</p>\n<pre><code class=\"language-mjs\">import sqlite from 'sqlite';\n</code></pre>\n<pre><code class=\"language-cjs\">const sqlite = require('sqlite');\n</code></pre>\n<p>The following example shows the basic usage of the <code>node:sqlite</code> module to open\nan in-memory database, write data to the database, and then read the data back.</p>\n<pre><code class=\"language-mjs\">import { DatabaseSync } from 'node:sqlite';\nconst database = new DatabaseSync(':memory:');\n\n// Execute SQL statements from strings.\ndatabase.exec(`\n  CREATE TABLE data(\n    key INTEGER PRIMARY KEY,\n    value TEXT\n  ) STRICT\n`);\n// Create a prepared statement to insert data into the database.\nconst insert = database.prepare('INSERT INTO data (key, value) VALUES (?, ?)');\n// Execute the prepared statement with bound values.\ninsert.run(1, 'hello');\ninsert.run(2, 'world');\n// Create a prepared statement to read data from the database.\nconst query = database.prepare('SELECT * FROM data ORDER BY key');\n// Execute the prepared statement and log the result set.\nconsole.log(query.all());\n// Prints: [ { key: 1, value: 'hello' }, { key: 2, value: 'world' } ]\n</code></pre>\n<pre><code class=\"language-cjs\">'use strict';\nconst { DatabaseSync } = require('node:sqlite');\nconst database = new DatabaseSync(':memory:');\n\n// Execute SQL statements from strings.\ndatabase.exec(`\n  CREATE TABLE data(\n    key INTEGER PRIMARY KEY,\n    value TEXT\n  ) STRICT\n`);\n// Create a prepared statement to insert data into the database.\nconst insert = database.prepare('INSERT INTO data (key, value) VALUES (?, ?)');\n// Execute the prepared statement with bound values.\ninsert.run(1, 'hello');\ninsert.run(2, 'world');\n// Create a prepared statement to read data from the database.\nconst query = database.prepare('SELECT * FROM data ORDER BY key');\n// Execute the prepared statement and log the result set.\nconsole.log(query.all());\n// Prints: [ { key: 1, value: 'hello' }, { key: 2, value: 'world' } ]\n</code></pre>",
      "classes": [
        {
          "textRaw": "Class: `DatabaseSync`",
          "type": "class",
          "name": "DatabaseSync",
          "meta": {
            "added": [
              "v22.5.0"
            ],
            "changes": []
          },
          "desc": "<p>This class represents a single <a href=\"https://www.sqlite.org/c3ref/sqlite3.html\">connection</a> to a SQLite database. All APIs\nexposed by this class execute synchronously.</p>",
          "methods": [
            {
              "textRaw": "`database.close()`",
              "type": "method",
              "name": "close",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>Closes the database connection. An exception is thrown if the database is not\nopen. This method is a wrapper around <a href=\"https://www.sqlite.org/c3ref/close.html\"><code>sqlite3_close_v2()</code></a>.</p>"
            },
            {
              "textRaw": "`database.exec(sql)`",
              "type": "method",
              "name": "exec",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`sql` {string} A SQL string to execute.",
                      "name": "sql",
                      "type": "string",
                      "desc": "A SQL string to execute."
                    }
                  ]
                }
              ],
              "desc": "<p>This method allows one or more SQL statements to be executed without returning\nany results. This method is useful when executing SQL statements read from a\nfile. This method is a wrapper around <a href=\"https://www.sqlite.org/c3ref/exec.html\"><code>sqlite3_exec()</code></a>.</p>"
            },
            {
              "textRaw": "`database.open()`",
              "type": "method",
              "name": "open",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>Opens the database specified in the <code>location</code> argument of the <code>DatabaseSync</code>\nconstructor. This method should only be used when the database is not opened via\nthe constructor. An exception is thrown if the database is already open.</p>"
            },
            {
              "textRaw": "`database.prepare(sql)`",
              "type": "method",
              "name": "prepare",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "return": {
                    "textRaw": "Returns: {StatementSync} The prepared statement.",
                    "name": "return",
                    "type": "StatementSync",
                    "desc": "The prepared statement."
                  },
                  "params": [
                    {
                      "textRaw": "`sql` {string} A SQL string to compile to a prepared statement.",
                      "name": "sql",
                      "type": "string",
                      "desc": "A SQL string to compile to a prepared statement."
                    }
                  ]
                }
              ],
              "desc": "<p>Compiles a SQL statement into a <a href=\"https://www.sqlite.org/c3ref/stmt.html\">prepared statement</a>. This method is a wrapper\naround <a href=\"https://www.sqlite.org/c3ref/prepare.html\"><code>sqlite3_prepare_v2()</code></a>.</p>"
            }
          ],
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`location` {string} The location of the database. A SQLite database can be stored in a file or completely [in memory][]. To use a file-backed database, the location should be a file path. To use an in-memory database, the location should be the special name `':memory:'`.",
                  "name": "location",
                  "type": "string",
                  "desc": "The location of the database. A SQLite database can be stored in a file or completely [in memory][]. To use a file-backed database, the location should be a file path. To use an in-memory database, the location should be the special name `':memory:'`."
                },
                {
                  "textRaw": "`options` {Object} Configuration options for the database connection. The following options are supported:",
                  "name": "options",
                  "type": "Object",
                  "desc": "Configuration options for the database connection. The following options are supported:",
                  "options": [
                    {
                      "textRaw": "`open` {boolean} If `true`, the database is opened by the constructor. When this value is `false`, the database must be opened via the `open()` method. **Default:** `true`.",
                      "name": "open",
                      "type": "boolean",
                      "default": "`true`",
                      "desc": "If `true`, the database is opened by the constructor. When this value is `false`, the database must be opened via the `open()` method."
                    }
                  ]
                }
              ],
              "desc": "<p>Constructs a new <code>DatabaseSync</code> instance.</p>"
            }
          ]
        },
        {
          "textRaw": "Class: `StatementSync`",
          "type": "class",
          "name": "StatementSync",
          "meta": {
            "added": [
              "v22.5.0"
            ],
            "changes": []
          },
          "desc": "<p>This class represents a single <a href=\"https://www.sqlite.org/c3ref/stmt.html\">prepared statement</a>. This class cannot be\ninstantiated via its constructor. Instead, instances are created via the\n<code>database.prepare()</code> method. All APIs exposed by this class execute\nsynchronously.</p>\n<p>A prepared statement is an efficient binary representation of the SQL used to\ncreate it. Prepared statements are parameterizable, and can be invoked multiple\ntimes with different bound values. Parameters also offer protection against\n<a href=\"https://en.wikipedia.org/wiki/SQL_injection\">SQL injection</a> attacks. For these reasons, prepared statements are preferred\nover hand-crafted SQL strings when handling user input.</p>",
          "methods": [
            {
              "textRaw": "`statement.all([namedParameters][, ...anonymousParameters])`",
              "type": "method",
              "name": "all",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "return": {
                    "textRaw": "Returns: {Array} An array of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of the row.",
                    "name": "return",
                    "type": "Array",
                    "desc": "An array of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of the row."
                  },
                  "params": [
                    {
                      "textRaw": "`namedParameters` {Object} An optional object used to bind named parameters. The keys of this object are used to configure the mapping.",
                      "name": "namedParameters",
                      "type": "Object",
                      "desc": "An optional object used to bind named parameters. The keys of this object are used to configure the mapping."
                    },
                    {
                      "textRaw": "`...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or more values to bind to anonymous parameters.",
                      "name": "...anonymousParameters",
                      "type": "null|number|bigint|string|Buffer|Uint8Array",
                      "desc": "Zero or more values to bind to anonymous parameters."
                    }
                  ]
                }
              ],
              "desc": "<p>This method executes a prepared statement and returns all results as an array of\nobjects. If the prepared statement does not return any results, this method\nreturns an empty array. The prepared statement <a href=\"https://www.sqlite.org/c3ref/bind_blob.html\">parameters are bound</a> using\nthe values in <code>namedParameters</code> and <code>anonymousParameters</code>.</p>"
            },
            {
              "textRaw": "`statement.expandedSQL()`",
              "type": "method",
              "name": "expandedSQL",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "return": {
                    "textRaw": "Returns: {string} The source SQL expanded to include parameter values.",
                    "name": "return",
                    "type": "string",
                    "desc": "The source SQL expanded to include parameter values."
                  },
                  "params": []
                }
              ],
              "desc": "<p>This method returns the source SQL of the prepared statement with parameter\nplaceholders replaced by values. This method is a wrapper around\n<a href=\"https://www.sqlite.org/c3ref/expanded_sql.html\"><code>sqlite3_expanded_sql()</code></a>.</p>"
            },
            {
              "textRaw": "`statement.get([namedParameters][, ...anonymousParameters])`",
              "type": "method",
              "name": "get",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "return": {
                    "textRaw": "Returns: {Object|undefined} An object corresponding to the first row returned by executing the prepared statement. The keys and values of the object correspond to the column names and values of the row. If no rows were returned from the database then this method returns `undefined`.",
                    "name": "return",
                    "type": "Object|undefined",
                    "desc": "An object corresponding to the first row returned by executing the prepared statement. The keys and values of the object correspond to the column names and values of the row. If no rows were returned from the database then this method returns `undefined`."
                  },
                  "params": [
                    {
                      "textRaw": "`namedParameters` {Object} An optional object used to bind named parameters. The keys of this object are used to configure the mapping.",
                      "name": "namedParameters",
                      "type": "Object",
                      "desc": "An optional object used to bind named parameters. The keys of this object are used to configure the mapping."
                    },
                    {
                      "textRaw": "`...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or more values to bind to anonymous parameters.",
                      "name": "...anonymousParameters",
                      "type": "null|number|bigint|string|Buffer|Uint8Array",
                      "desc": "Zero or more values to bind to anonymous parameters."
                    }
                  ]
                }
              ],
              "desc": "<p>This method executes a prepared statement and returns the first result as an\nobject. If the prepared statement does not return any results, this method\nreturns <code>undefined</code>. The prepared statement <a href=\"https://www.sqlite.org/c3ref/bind_blob.html\">parameters are bound</a> using the\nvalues in <code>namedParameters</code> and <code>anonymousParameters</code>.</p>"
            },
            {
              "textRaw": "`statement.run([namedParameters][, ...anonymousParameters])`",
              "type": "method",
              "name": "run",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "return": {
                    "textRaw": "Returns: {Object}",
                    "name": "return",
                    "type": "Object",
                    "options": [
                      {
                        "textRaw": "`changes`: {number|bigint} The number of rows modified, inserted, or deleted by the most recently completed `INSERT`, `UPDATE`, or `DELETE` statement. This field is either a number or a `BigInt` depending on the prepared statement's configuration. This property is the result of [`sqlite3_changes64()`][].",
                        "name": "changes",
                        "type": "number|bigint",
                        "desc": "The number of rows modified, inserted, or deleted by the most recently completed `INSERT`, `UPDATE`, or `DELETE` statement. This field is either a number or a `BigInt` depending on the prepared statement's configuration. This property is the result of [`sqlite3_changes64()`][]."
                      },
                      {
                        "textRaw": "`lastInsertRowid`: {number|bigint} The most recently inserted rowid. This field is either a number or a `BigInt` depending on the prepared statement's configuration. This property is the result of [`sqlite3_last_insert_rowid()`][].",
                        "name": "lastInsertRowid",
                        "type": "number|bigint",
                        "desc": "The most recently inserted rowid. This field is either a number or a `BigInt` depending on the prepared statement's configuration. This property is the result of [`sqlite3_last_insert_rowid()`][]."
                      }
                    ]
                  },
                  "params": [
                    {
                      "textRaw": "`namedParameters` {Object} An optional object used to bind named parameters. The keys of this object are used to configure the mapping.",
                      "name": "namedParameters",
                      "type": "Object",
                      "desc": "An optional object used to bind named parameters. The keys of this object are used to configure the mapping."
                    },
                    {
                      "textRaw": "`...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or more values to bind to anonymous parameters.",
                      "name": "...anonymousParameters",
                      "type": "null|number|bigint|string|Buffer|Uint8Array",
                      "desc": "Zero or more values to bind to anonymous parameters."
                    }
                  ]
                }
              ],
              "desc": "<p>This method executes a prepared statement and returns an object summarizing the\nresulting changes. The prepared statement <a href=\"https://www.sqlite.org/c3ref/bind_blob.html\">parameters are bound</a> using the\nvalues in <code>namedParameters</code> and <code>anonymousParameters</code>.</p>"
            },
            {
              "textRaw": "`statement.setAllowBareNamedParameters(enabled)`",
              "type": "method",
              "name": "setAllowBareNamedParameters",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`enabled` {boolean} Enables or disables support for binding named parameters without the prefix character.",
                      "name": "enabled",
                      "type": "boolean",
                      "desc": "Enables or disables support for binding named parameters without the prefix character."
                    }
                  ]
                }
              ],
              "desc": "<p>The names of SQLite parameters begin with a prefix character. By default,\n<code>node:sqlite</code> requires that this prefix character is present when binding\nparameters. However, with the exception of dollar sign character, these\nprefix characters also require extra quoting when used in object keys.</p>\n<p>To improve ergonomics, this method can be used to also allow bare named\nparameters, which do not require the prefix character in JavaScript code. There\nare several caveats to be aware of when enabling bare named parameters:</p>\n<ul>\n<li>The prefix character is still required in SQL.</li>\n<li>The prefix character is still allowed in JavaScript. In fact, prefixed names\nwill have slightly better binding performance.</li>\n<li>Using ambiguous named parameters, such as <code>$k</code> and <code>@k</code>, in the same prepared\nstatement will result in an exception as it cannot be determined how to bind\na bare name.</li>\n</ul>"
            },
            {
              "textRaw": "`statement.setReadBigInts(enabled)`",
              "type": "method",
              "name": "setReadBigInts",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`enabled` {boolean} Enables or disables the use of `BigInt`s when reading `INTEGER` fields from the database.",
                      "name": "enabled",
                      "type": "boolean",
                      "desc": "Enables or disables the use of `BigInt`s when reading `INTEGER` fields from the database."
                    }
                  ]
                }
              ],
              "desc": "<p>When reading from the database, SQLite <code>INTEGER</code>s are mapped to JavaScript\nnumbers by default. However, SQLite <code>INTEGER</code>s can store values larger than\nJavaScript numbers are capable of representing. In such cases, this method can\nbe used to read <code>INTEGER</code> data using JavaScript <code>BigInt</code>s. This method has no\nimpact on database write operations where numbers and <code>BigInt</code>s are both\nsupported at all times.</p>"
            },
            {
              "textRaw": "`statement.sourceSQL()`",
              "type": "method",
              "name": "sourceSQL",
              "meta": {
                "added": [
                  "v22.5.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "return": {
                    "textRaw": "Returns: {string} The source SQL used to create this prepared statement.",
                    "name": "return",
                    "type": "string",
                    "desc": "The source SQL used to create this prepared statement."
                  },
                  "params": []
                }
              ],
              "desc": "<p>This method returns the source SQL of the prepared statement. This method is a\nwrapper around <a href=\"https://www.sqlite.org/c3ref/expanded_sql.html\"><code>sqlite3_sql()</code></a>.</p>"
            }
          ],
          "modules": [
            {
              "textRaw": "Type conversion between JavaScript and SQLite",
              "name": "type_conversion_between_javascript_and_sqlite",
              "desc": "<p>When Node.js writes to or reads from SQLite it is necessary to convert between\nJavaScript data types and SQLite's <a href=\"https://www.sqlite.org/datatype3.html\">data types</a>. Because JavaScript supports\nmore data types than SQLite, only a subset of JavaScript types are supported.\nAttempting to write an unsupported data type to SQLite will result in an\nexception.</p>\n<table>\n<thead>\n<tr>\n<th>SQLite</th>\n<th>JavaScript</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>NULL</code></td>\n<td><code>null</code></td>\n</tr>\n<tr>\n<td><code>INTEGER</code></td>\n<td><code>number</code> or <code>BigInt</code></td>\n</tr>\n<tr>\n<td><code>REAL</code></td>\n<td><code>number</code></td>\n</tr>\n<tr>\n<td><code>TEXT</code></td>\n<td><code>string</code></td>\n</tr>\n<tr>\n<td><code>BLOB</code></td>\n<td><code>Uint8Array</code></td>\n</tr>\n</tbody>\n</table>",
              "type": "module",
              "displayName": "Type conversion between JavaScript and SQLite"
            }
          ]
        }
      ],
      "type": "module",
      "displayName": "SQLite"
    }
  ]
}