{"_id":"@allnulled/sqlite-polyfill","_rev":"1-10c4380bfe5a8bfd615781cddff541c9","name":"@allnulled/sqlite-polyfill","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@allnulled/sqlite-polyfill","version":"1.0.0","keywords":[],"author":"","license":"ISC","_id":"@allnulled/sqlite-polyfill@1.0.0","maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"dist":{"shasum":"a43a620f13af2c1dbfc3b61a7bd1fa0c50a7c599","tarball":"https://registry.npmjs.org/@allnulled/sqlite-polyfill/-/sqlite-polyfill-1.0.0.tgz","fileCount":8,"integrity":"sha512-IOA/3bYXhEviEZG2ATxP+36TV59VMKEpnSOtC5Lsof2CWHhgMPl71TJBSUMZlRYO1ASMk4sL93p5iwCdwxGo+Q==","signatures":[{"sig":"MEUCIQCLW5UJFT9hmIrBXPAsn2SfUG3tbnf9iyi2QiS2KwNBawIgKUUFjwTFIZUdzG4cT1bdL2/w4zuT3y2KOSmDKBOgD9g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":713962},"main":"sqlite-polyfill.js","gitHead":"eb468b4f814fa237453c62f15c339401ac4b021b","scripts":{"test":"node test/test.js","test:browser":"npx http-server -c-1 test -o"},"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"_npmVersion":"9.6.7","description":"SQLite Polyfill. Cross-environment: same API for Node.js and browser.","directories":{},"_nodeVersion":"18.17.1","dependencies":{"sqlite3":"^5.1.7"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sqlite-polyfill_1.0.0_1734517037016_0.8103326887723601","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@allnulled/sqlite-polyfill","version":"1.0.1","description":"SQLite Polyfill. Cross-environment: same API for Node.js and browser.","main":"sqlite-polyfill.js","scripts":{"test":"node test/test.js","test:browser":"npx http-server -c-1 test -o"},"keywords":[],"author":"","license":"ISC","dependencies":{"sqlite3":"^5.1.7"},"gitHead":"a12529ecf1b3955c377a59d65109d56ff1e9a1eb","_id":"@allnulled/sqlite-polyfill@1.0.1","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-5Lj4kpjDsGofK52fBoSMN73Dk7zBKFPdKuw/xLpcNcmMZYQNoElSHdJPaYH8GRcm9Q9OuY0hbLMX9jGid7MnOA==","shasum":"2b7584555591bdc84ad735757123d39504fa794c","tarball":"https://registry.npmjs.org/@allnulled/sqlite-polyfill/-/sqlite-polyfill-1.0.1.tgz","fileCount":9,"unpackedSize":723773,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDrQAaxAragJV8dNEl2OFYoWXxSJ2wECfsq6tvsYD3s0AIhALfcn0EkidsL8XutPbcN0nLUhcNbujIm3LIN4cAo/8n/"}]},"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"directories":{},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sqlite-polyfill_1.0.1_1734907096176_0.7374230130673385"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-18T10:17:16.911Z","modified":"2024-12-22T22:38:16.600Z","1.0.0":"2024-12-18T10:17:17.244Z","1.0.1":"2024-12-22T22:38:16.380Z"},"license":"ISC","keywords":[],"description":"SQLite Polyfill. Cross-environment: same API for Node.js and browser.","maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"readme":"# sqlite-polyfill\n\nUse [sqlite3](https://www.npmjs.com/package/sqlite3) on Node.js and [sql.js](https://sql.js.org/#/?id=usage) on browser, through the same API.\n\n## Installation\n\n```sh\nnpm install -s @allnulled/sqlite-polyfill\n```\n\n## Load\n\n**First, if you have doubts, take a look to the `test/test.js` file, which works on both environments, but see also `test/index.html` for the browser implementation. You'll see this explanation in action.**\n\nSo, despite the API is the same for both environments, there are some differences you must take care of on the load step.\n\nIn Node.js, with this conditional you can patch on browser, and set to global scope on node.js:\n\n```js\nif(typeof global !== \"undefined\") {\n    require(__dirname + \"/../sqlite-polyfill.js\");\n}\n```\n\nIn browser, though, you have to load the polyfill as script tag, and the [sql.js](https://sql.js.org) with its **wasm** file like so:\n\n```html\n<script src=\"sqljs-wasm/sql-wasm.js\"></script>\n<script src=\"sqlite-polyfill/sqlite-polyfill.js\"></script>\n```\n\nThen, you will have to copy the following files and integrate them in your HTML, in this same order:\n- `test/sqljs-wasm/sql-wasm.js`\n- `test/sqljs-wasm/sql-wasm.wasm` (not included by script, but by API `init` method)\n- `test/sqlite-polyfill/sqlite-polyfill.js`\n\n\n## Usage\n\nThe last conflictive point is the `init` function, which takes parameters for both environments.\n\n```js\nconst db = new SQLitePolyfill();\n// @ATTENTION!\n//   - In browser, 1st parameter is the key in localStorage\n//   - In node.js, 2nd parameter is ignored. See this path is relative to where you put the `test/sqljs-wasm/sql-wasm.wasm`\nawait db.init('example.db', \"sqljs-wasm/$filename\");\n\nawait db.run(\"CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)\");\nawait db.run(\"INSERT INTO test (name) VALUES (?)\", [\"Alice\"]);\n\nconst rows = await db.all(\"SELECT * FROM test\");\nconsole.log(rows);\n\nawait db.close();\n```\n\n## Use cases\n\nThis library can be useful to create (1) cross-environment (2) database-oriented scripts (3) based on SQL/SQLite.\n\n## Extra features\n\nThe polyfill comes with some extra advantages that the libraries may not come. For example:\n\n- Persistence for both\n   - patched using localStorage in browser\n   - the localStorage ID is directly the same name of the file. For now I don't see any problem about this.\n\n\n## Test\n\nThis is an example of how to use it in node.js and browser with the same script:\n\n```js\n(async () => {\n  if(typeof global !== \"undefined\") {\n    require(__dirname + \"/../sqlite-polyfill.js\");\n  }\n  const db = new SQLitePolyfill();\n  // @ATTENTION!\n  //   - In browser, 1st parameter is the key in localStorage\n  //   - In node.js, 2nd parameter is ignored. See this path is relative to where you put the `test/sqljs-wasm/sql-wasm.wasm`\n  await db.init('example.db', \"sqljs-wasm/$filename\");\n\n  await db.run(\"CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)\");\n  await db.run(\"INSERT INTO test (name) VALUES (?)\", [\"Alice\"]);\n\n  const rows = await db.all(\"SELECT * FROM test\");\n  console.log(rows);\n\n  await db.close();\n})();\n```\n\nYes, the same than before. I think it is enough clear. The test is imported from node and from browser, and works for both.\n\nYes, **sqlite**. With the WASM bindings and persistence for browser.","readmeFilename":"README.md"}