{"id":14460216,"url":"https://github.com/tndrle/node-sqlite3-wasm","last_synced_at":"2025-08-22T08:31:39.977Z","repository":{"id":64686950,"uuid":"576885999","full_name":"tndrle/node-sqlite3-wasm","owner":"tndrle","description":"WebAssembly port of SQLite3 for Node.js with file system access","archived":false,"fork":false,"pushed_at":"2024-04-20T16:15:08.000Z","size":7289,"stargazers_count":48,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-20T21:57:34.070Z","etag":null,"topics":["database","electron","filesystem","javascript","nodejs","persistent","platform-independent","sql","sqlite","sqlite3","typescript","wasm","webassembly"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tndrle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://www.paypal.com/donate/?hosted_button_id=9GPTJ4UZK9F92"}},"created_at":"2022-12-11T10:05:18.000Z","updated_at":"2024-05-31T21:46:07.716Z","dependencies_parsed_at":"2023-09-26T01:25:47.125Z","dependency_job_id":"f377f350-9202-41a5-918d-c929771be3f0","html_url":"https://github.com/tndrle/node-sqlite3-wasm","commit_stats":null,"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tndrle%2Fnode-sqlite3-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tndrle%2Fnode-sqlite3-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tndrle%2Fnode-sqlite3-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tndrle%2Fnode-sqlite3-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tndrle","download_url":"https://codeload.github.com/tndrle/node-sqlite3-wasm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230575851,"owners_count":18247484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","electron","filesystem","javascript","nodejs","persistent","platform-independent","sql","sqlite","sqlite3","typescript","wasm","webassembly"],"created_at":"2024-09-01T21:01:20.978Z","updated_at":"2025-08-22T08:31:39.966Z","avatar_url":"https://github.com/tndrle.png","language":"JavaScript","funding_links":["https://www.paypal.com/donate/?hosted_button_id=9GPTJ4UZK9F92"],"categories":["webassembly"],"sub_categories":[],"readme":"**_node-sqlite3-wasm_**\n\n[![npm](https://img.shields.io/npm/v/node-sqlite3-wasm.svg)](https://www.npmjs.com/package/node-sqlite3-wasm)\n[![SQLite](https://img.shields.io/badge/SQLite-3.50.4-blue)](https://www.sqlite.org/index.html)\n\n# WebAssembly build of SQLite3 for Node.js\n\n**_node-sqlite3-wasm_** is a port of [SQLite3](https://www.sqlite.org/) to\n[WebAssembly](https://webassembly.org/) for [Node.js](https://nodejs.org/) with\nfile system access. _node-sqlite3-wasm_ brings\n[SQLite3](https://www.sqlite.org/) to your [Node.js](https://nodejs.org/)\nenvironment without recompiling on every target platform. This is especially\nuseful for [Electron](https://www.electronjs.org/) applications.\n\nThe port to WebAssembly that SQLite introduced in version 3.40.0 only targets\nweb browsers but not Node.js. Other WebAssembly ports also target Node.js, most\nnotably [sql.js](https://github.com/sql-js/sql.js/), but none supports\npersistent storage with direct file access. There also exist native bindings\nlike [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) or\n[node-sqlite3](https://github.com/TryGhost/node-sqlite3). However, native\nbindings must be recompiled for every target platform or pre-built binaries must\nbe shipped. This is tedious, especially for Electron deployments.\n\n_node-sqlite3-wasm_ supports persistent storage with direct file access by\nimplementing an [SQLite OS Interface or \"VFS\"](https://www.sqlite.org/vfs.html)\nthat translates SQLite file access to [Node.js' file system\nAPI](https://nodejs.org/api/fs.html).\n\n_node-sqlite3-wasm_ is currently based on SQLite 3.50.4.\n\n## Getting Started\n\nTo install _node-sqlite3-wasm_, run\n\n```\nnpm install node-sqlite3-wasm\n```\n\nTo use it, run\n\n```js\nconst { Database } = require(\"node-sqlite3-wasm\");\nconst db = new Database(\"database.db\");\n```\n\n**Important:** _node-sqlite3-wasm_ is not fully garbage-collected. You **have to\nmanually close** a database, otherwise you risk **memory leaks** (see\n[`Database.close()`](#databaseclose)). Also, if you use prepared statements explicitly (see\n[`Database.prepare()`](#databasepreparesql---statement)), you **have to manually finalize** them. Alternatively, the\n[``Database``](#class-database) class provides the convenience methods\n\n- [`Database.all()`](#databaseallsql-values-options---rows)\n- [`Database.get()`](#databasegetsql-values-options---row)\n- [`Database.run()`](#databaserunsql-values---info)\n\nThese convenience methods use a prepared statement internally and take care of\nfinalizing it.\n\n**Note:** Foreign key support is enabled by default.\n\n## Example\n\n```js\nconst { Database } = require(\"node-sqlite3-wasm\");\nconst db = new Database(\"database.db\");\n\ndb.exec(\n  \"DROP TABLE IF EXISTS employees; \" +\n    \"CREATE TABLE IF NOT EXISTS employees (name TEXT, salary INTEGER)\"\n);\n\ndb.run(\"INSERT INTO employees VALUES (:n, :s)\", {\n  \":n\": \"James\",\n  \":s\": 50000,\n});\n\nconst r = db.all(\"SELECT * from employees\");\nconsole.log(r);\n// [ { name: 'James', salary: 50000 } ]\n\ndb.close();\n```\n\n## API\n\n- [`class Database`](#class-database)\n- [`class Statement`](#class-statement)\n- [`class SQLite3Error`](#class-sqlite3error)\n\n### `class Database`\n\nConstructor\n\n- [`new Database()`](#new-databasepath-options)\n\nMethods\n\n- [`Database.all()`](#databaseallsql-values-options---rows)\n- [`Database.close()`](#databaseclose)\n- [`Database.exec()`](#databaseexecsql)\n- [`Database.function()`](#databasefunctionname-func-options---this)\n- [`Database.get()`](#databasegetsql-values-options---row)\n- [`Database.prepare()`](#databasepreparesql---statement)\n- [`Database.run()`](#databaserunsql-values---info)\n\nProperties\n\n- [`Database.inTransaction`](#databaseintransaction)\n- [`Database.isOpen`](#databaseisopen)\n\n### `new Database(path, [options])`\n\nCreates a new database connection. By default, the database file is created if\nit doesn't exist.\n\n**Important:** You **have to manually close** the database, otherwise you risk\n**memory leaks** (see [`Database.close()`](#databaseclose)).\n\nArguments\n\n- `path`: the path to the database file\n- `options` (optional)\n  - `fileMustExist` (default: `false`): if the database file does not exist it\n    will not be created. Instead an [``SQLite3Error``](#class-sqlite3error) will\n    be thrown. This option is ignored if `readOnly` is `true`.\n  - `readOnly` (default: `false`): opens the database in read-only mode\n\n```js\nconst db = new Database(\"database.db\");\n```\n\n```js\nconst db = new Database(\"database.db\", { fileMustExist: true });\n```\n\n### `Database.all(sql, [values, options]) -\u003e rows`\n\nCreates a prepared statement, executes it with the given values and returns the\nresulting rows as an array of objects. The prepared statement is finalized\nautomatically.\n\nArguments\n\n- `sql`: string containing the SQL statement\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n- `options` (optional)\n  - `expand` (default: `false`): if `true`, each returned row is a nested object\n    with keys corresponding to tables in the query. If a result column is an\n    expression or subquery, it will be returned under the key `$`.\n\n```js\ndb.all(\"SELECT * FROM book\");\n```\n\n```js\ndb.all(\"SELECT * FROM book WHERE title = ?\", \"The Little Prince\");\n```\n\n```js\ndb.all(\"SELECT * FROM book WHERE title = :t\", { \":t\": \"The Little Prince\" });\n```\n\n```js\ndb.all(\"SELECT * FROM book WHERE title IN (?, ?)\", [\n  \"The Little Prince\",\n  \"The Hobbit\",\n]);\n```\n\n### `Database.close()`\n\nCloses the database.\n\n**Important:** You **have to manually close** the database, otherwise you risk\n**memory leaks**.\n\n**Important:** Closing the database with [`Database.close()`](#databaseclose) does not automatically\nfinalize pending prepared statements.\n\n```js\ndb.close();\n```\n\n### `Database.exec(sql)`\n\nExecutes the given SQL string. The SQL string may contain several\nsemicolon-separated statements.\n\n```js\ndb.exec(\n  \"DROP TABLE IF EXISTS book; CREATE TABLE book (id INTEGER PRIMARY KEY, title TEXT)\"\n);\n```\n\n### `Database.function(name, func, [options]) -\u003e this`\n\nRegisters a user-defined function.\n\nArguments\n\n- `name`: the name of the function\n- `func`: the implementation of the function\n- `options` (optional)\n  - `deterministic` (default: `false`): if `true`, the function is considered\n    [deterministic](https://www.sqlite.org/deterministic.html)\n\n```js\ndb.function(\"regexp\", (y, x) =\u003e new RegExp(y, \"i\").test(x), {\n  deterministic: true,\n});\ndb.all(\"SELECT * FROM book WHERE title REGEXP ?\", \".*little.*\");\n```\n\n### `Database.get(sql, [values, options]) -\u003e row`\n\nCreates a prepared statement, executes it with the given values and returns the\nfirst resulting row as an object. The prepared statement is finalized\nautomatically.\n\nArguments\n\n- `sql`: string containing the SQL statement\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n- `options` (optional)\n  - `expand` (default: `false`): if `true`, the returned row is a nested object\n    with keys corresponding to tables in the query. If a result column is an\n    expression or subquery, it will be returned under the key `$`.\n\n```js\ndb.get(\"SELECT * FROM book WHERE id = ?\", 7);\n```\n\n```js\ndb.get(\"SELECT * FROM book WHERE id = $id\", { $id: 7 });\n```\n\n```js\ndb.get(\"SELECT * FROM book WHERE id = ? AND title = ?\", [\n  3,\n  \"The Little Prince\",\n]);\n```\n\n### `Database.prepare(sql) -\u003e Statement`\n\nCreates a prepared statement from the given SQL string.\n\n**Important:** You **have to manually finalize** a statement, otherwise you risk\n**memory leaks**. See [``Statement``](#class-statement) and, in particular,\n[`Statement.finalize()`](#statementfinalize).\n\n```js\nconst stmt = db.prepare(\"INSERT INTO book (title) VALUES (?)\");\ntry {\n  // do something with the statement here\n} finally {\n  stmt.finalize();\n}\n```\n\nThe [``Database``](#class-database) class provides the convenience methods\n\n- [`Database.all()`](#databaseallsql-values-options---rows)\n- [`Database.get()`](#databasegetsql-values-options---row)\n- [`Database.run()`](#databaserunsql-values---info)\n\nThese convenience methods use a prepared statement internally and take care of\nfinalizing it.\n\n### `Database.run(sql, [values]) -\u003e info`\n\nCreates a prepared statement, executes it with the given values and returns an\nobject with the properties `changes` and `lastInsertRowid` describing the number\nof modified rows and the id of the last row inserted. `lastInsertRowid` is a\n[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)\nif its value exceeds\n[`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER).\nThe prepared statement is finalized automatically.\n\nArguments\n\n- `sql`: string containing the SQL statement\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n\n```js\ndb.run(\"INSERT INTO book (title) VALUES (?)\", \"The Little Prince\");\n```\n\n```js\ndb.run(\"INSERT INTO book VALUES (?, ?)\", [10, \"The Little Prince\"]);\n```\n\n```js\ndb.run(\"INSERT INTO book VALUES (@id, :title)\", {\n  \"@id\": 10,\n  \":title\": \"The Little Prince\",\n});\n```\n\n### `Database.inTransaction`\n\nProperty determining whether the database is currently in a transaction.\n\n```js\nconst stmt = db.prepare(\"INSERT INTO book (title) VALUES (?)\");\ntry {\n  db.exec(\"BEGIN TRANSACTION\");\n  stmt.run(\"The Little Prince\");\n  stmt.run(\"The Hobbit\");\n  db.exec(\"COMMIT\");\n} catch (err) {\n  if (db.inTransaction) db.exec(\"ROLLBACK\");\n  console.log(err);\n} finally {\n  stmt.finalize();\n}\n```\n\n### `Database.isOpen`\n\nProperty determining whether the database is currently open.\n\n### `class Statement`\n\nMethods\n\n- [`Statement.all()`](#statementallvalues-options---rows)\n- [`Statement.finalize()`](#statementfinalize)\n- [`Statement.get()`](#statementgetvalues-options---row)\n- [`Statement.iterate()`](#statementiteratevalues-options---iterableiteratorrow)\n- [`Statement.run()`](#statementrunvalues---info)\n\nProperties\n\n- [`Statement.database`](#statementdatabase)\n- [`Statement.isFinalized`](#statementisfinalized)\n\n**Important:** You **have to manually finalize** a statement, otherwise you risk\n**memory leaks** (see [`Statement.finalize()`](#statementfinalize)).\n\n```js\nconst stmt = db.prepare(\"SELECT * FROM book WHERE id = ?\");\ntry {\n  // do something with the statement here\n} finally {\n  stmt.finalize();\n}\n```\n\nAs an alternative, the [``Database``](#class-database) class provides the\nconvenience methods\n\n- [`Database.all()`](#databaseallsql-values-options---rows)\n- [`Database.get()`](#databasegetsql-values-options---row)\n- [`Database.run()`](#databaserunsql-values---info)\n\nThese convenience methods use a prepared statement internally and take care of\nfinalizing it.\n\n### `Statement.all([values, options]) -\u003e rows`\n\nExecutes the prepared statement with the given values and returns the resulting\nrows as an array of objects.\n\nArguments\n\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n- `options` (optional)\n  - `expand` (default: `false`): if `true`, each returned row is a nested object\n    with keys corresponding to tables in the query. If a result column is an\n    expression or subquery, it will be returned under the key `$`.\n\nSee also [`Database.all()`](#databaseallsql-values-options---rows)\n\n### `Statement.finalize()`\n\nFinalizes the statement and frees all allocated memory. Once a statement has\nbeen finalized, it cannot be used anymore.\n\n**Important:** You **have to manually finalize** a statement, otherwise you risk\n**memory leaks**.\n\n**Important:** Closing the database with [`Database.close()`](#databaseclose) does not automatically\nfinalize pending prepared statements.\n\n### `Statement.get([values, options]) -\u003e row`\n\nExecutes the prepared statement with the given values and returns the first\nresulting row as an object.\n\nArguments\n\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n- `options` (optional)\n  - `expand` (default: `false`): if `true`, the returned row is a nested object\n    with keys corresponding to tables in the query. If a result column is an\n    expression or subquery, it will be returned under the key `$`.\n\nSee also [`Database.get()`](#databasegetsql-values-options---row)\n\n### `Statement.iterate([values, options]) -\u003e IterableIterator\u003crow\u003e`\n\nExecutes the prepared statement with the given values and returns the resulting\nrows as an iterator of objects.\n\nArguments\n\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n- `options` (optional)\n  - `expand` (default: `false`): if `true`, each returned row is a nested object\n    with keys corresponding to tables in the query. If a result column is an\n    expression or subquery, it will be returned under the key `$`.\n\n### `Statement.run([values]) -\u003e info`\n\nExecutes the prepared statement with the given values and returns an object with\nthe properties `changes` and `lastInsertRowid` describing the number of modified\nrows and the id of the last row inserted. `lastInsertRowid` is a\n[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)\nif its value exceeds\n[`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER).\n\nArguments\n\n- `values` (optional): values to bind to the statement's parameters. Either a\n  single value, an array, or an object in case of named parameters.\n\nSee also [`Database.run()`](#databaserunsql-values---info)\n\n### `Statement.database`\n\nThe [``Database``](#class-database) object that instantiated this statement.\n\n### `Statement.isFinalized`\n\nProperty determining whether the statement has been finalized using\n[`Statement.finalize()`](#statementfinalize). A finalized statement must not be used anymore.\n\n### `class SQLite3Error`\n\n_node-sqlite3-wasm_ throws an `SQLite3Error` whenever an error in SQLite\nor in the API occurs. `SQLite3Error` is a subclass of `Error`.\n\n## Notes About Types\n\n### Numbers\n\nJavaScript's\n[`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number?retiredLocale=de)\ntype is a double-precision 64-bit binary format IEEE 754 value. Integers can\nonly be represented without loss of precision in the range -2\u003csup\u003e53\u003c/sup\u003e + 1\nto 2\u003csup\u003e53\u003c/sup\u003e - 1, inclusive. SQLite3 works with [8-byte signed\nintegers](https://www.sqlite.org/datatype3.html) with a range of -2\u003csup\u003e63\u003c/sup\u003e\nto 2\u003csup\u003e63\u003c/sup\u003e - 1, inclusive. Since this range exceeds the range of safe\nintegers in JavaScript, _node-sqlite3-wasm_ automatically converts integers\noutside this safe range to\n[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).\nIt is your responsibility to ensure that you handle the returned values, whether\n`Number` or `BigInt`, correctly. _node-sqlite3-wasm_ also allows you to input\n`BigInt` values as query parameters, or arguments or return values of\nuser-defined functions.\n\n### Binary Large Objects (BLOBs)\n\nAn SQLite Binary Large Object (BLOB) is represented by a\n[`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)\nin JavaScript.\n\n## Building\n\n[Docker](https://www.docker.com) and [npm](https://www.npmjs.com) are required\nfor building. [Mocha](https://mochajs.org) is required to run tests.\n\nTo build _node-sqlite3-wasm_, simply run\n\n```\nnpm run build\n```\n\nThis will download the [emscripten Docker\nimage](https://hub.docker.com/r/emscripten/emsdk) and the [SQLite source\nfiles](https://www.sqlite.org/download.html). Then it will compile the project\nsource files and generate `dist/node-sqlite3-wasm.js` and\n`dist/node-sqlite3-wasm.wasm`.\n\n## License\n\n_node-sqlite3-wasm_ is\n[MIT](https://github.com/tndrle/node-sqlite3-wasm/blob/main/LICENSE) licensed.\n\nParts of the code are from [sql.js](https://github.com/sql-js/sql.js), which is\nalso MIT licensed. SQLite is in the [public\ndomain](https://www.sqlite.org/copyright.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftndrle%2Fnode-sqlite3-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftndrle%2Fnode-sqlite3-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftndrle%2Fnode-sqlite3-wasm/lists"}