{"id":19293651,"url":"https://github.com/tursodatabase/libsql-wasm-experimental","last_synced_at":"2025-04-22T07:32:21.661Z","repository":{"id":215591309,"uuid":"739303863","full_name":"tursodatabase/libsql-wasm-experimental","owner":"tursodatabase","description":"libSQL WebAssembly build packaged for TypeScript/JavaScript","archived":false,"fork":false,"pushed_at":"2024-10-31T13:27:50.000Z","size":6036,"stargazers_count":35,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-01T20:51:25.572Z","etag":null,"topics":["javascript","libsql","sqlite3","webassembly"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tursodatabase.png","metadata":{"files":{"readme":"README-upstream.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-01-05T08:43:30.000Z","updated_at":"2025-03-14T12:58:03.000Z","dependencies_parsed_at":"2024-01-05T10:34:38.750Z","dependency_job_id":"74b1348c-0ac3-4de0-b364-7b07a0909523","html_url":"https://github.com/tursodatabase/libsql-wasm-experimental","commit_stats":null,"previous_names":["penberg/libsql-wasm","tursodatabase/libsql-wasm-experimental"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tursodatabase%2Flibsql-wasm-experimental","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tursodatabase%2Flibsql-wasm-experimental/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tursodatabase%2Flibsql-wasm-experimental/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tursodatabase%2Flibsql-wasm-experimental/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tursodatabase","download_url":"https://codeload.github.com/tursodatabase/libsql-wasm-experimental/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250195054,"owners_count":21390230,"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":["javascript","libsql","sqlite3","webassembly"],"created_at":"2024-11-09T22:35:37.384Z","updated_at":"2025-04-22T07:32:20.932Z","avatar_url":"https://github.com/tursodatabase.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLite Wasm\n\nSQLite Wasm conveniently wrapped as an ES Module.\n\n\u003e **Warning**\n\u003e\n\u003e This project wraps the code of\n\u003e [SQLite Wasm](https://sqlite.org/wasm/doc/trunk/index.md) with _no_ changes,\n\u003e apart from added TypeScript types. Please do _not_ file issues or feature\n\u003e requests regarding the underlying SQLite Wasm code here. Instead, please\n\u003e follow the\n\u003e [SQLite bug filing instructions](https://www.sqlite.org/src/wiki?name=Bug+Reports).\n\u003e Filing TypeScript type related issues and feature requests is fine.\n\n## Installation\n\n```bash\nnpm install @sqlite.org/sqlite-wasm\n```\n\n## Usage\n\nThere are three ways to use SQLite Wasm:\n\n- [in the main thread with a wrapped worker](#in-a-wrapped-worker-with-opfs-if-available)\n  (🏆 preferred option)\n- [in a worker](#in-a-worker-with-opfs-if-available)\n- [in the main thread](#in-the-main-thread-without-opfs)\n\nOnly the worker versions allow you to use the origin private file system (OPFS)\nstorage back-end.\n\n### In a wrapped worker (with OPFS if available):\n\n\u003e **Warning**\n\u003e\n\u003e For this to work, you need to set the following headers on your server:\n\u003e\n\u003e `Cross-Origin-Opener-Policy: same-origin`\n\u003e\n\u003e `Cross-Origin-Embedder-Policy: require-corp`\n\n```js\nimport { sqlite3Worker1Promiser } from '@sqlite.org/sqlite-wasm';\n\nconst log = (...args) =\u003e console.log(...args);\nconst error = (...args) =\u003e console.error(...args);\n\n(async () =\u003e {\n  try {\n    log('Loading and initializing SQLite3 module...');\n\n    const promiser = await new Promise((resolve) =\u003e {\n      const _promiser = sqlite3Worker1Promiser({\n        onready: () =\u003e {\n          resolve(_promiser);\n        },\n      });\n    });\n\n    log('Done initializing. Running demo...');\n\n    let response;\n\n    response = await promiser('config-get', {});\n    log('Running SQLite3 version', response.result.version.libVersion);\n\n    response = await promiser('open', {\n      filename: 'file:mydb.sqlite3?vfs=opfs',\n    });\n    const { dbId } = response;\n    log(\n      'OPFS is available, created persisted database at',\n      response.result.filename.replace(/^file:(.*?)\\?vfs=opfs$/, '$1'),\n    );\n    // Your SQLite code here.\n  } catch (err) {\n    if (!(err instanceof Error)) {\n      err = new Error(err.result.message);\n    }\n    error(err.name, err.message);\n  }\n})();\n```\n\nThe `promiser` object above implements the\n[Worker1 API](https://sqlite.org/wasm/doc/trunk/api-worker1.md#worker1-methods).\n\n### In a worker (with OPFS if available):\n\n\u003e **Warning**\n\u003e\n\u003e For this to work, you need to set the following headers on your server:\n\u003e\n\u003e `Cross-Origin-Opener-Policy: same-origin`\n\u003e\n\u003e `Cross-Origin-Embedder-Policy: require-corp`\n\n```js\n// In `main.js`.\nconst worker = new Worker('worker.js', { type: 'module' });\n```\n\n```js\n// In `worker.js`.\nimport sqlite3InitModule from '@sqlite.org/sqlite-wasm';\n\nconst log = (...args) =\u003e console.log(...args);\nconst error = (...args) =\u003e console.error(...args);\n\nconst start = function (sqlite3) {\n  log('Running SQLite3 version', sqlite3.version.libVersion);\n  let db;\n  if ('opfs' in sqlite3) {\n    db = new sqlite3.oo1.OpfsDb('/mydb.sqlite3');\n    log('OPFS is available, created persisted database at', db.filename);\n  } else {\n    db = new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');\n    log('OPFS is not available, created transient database', db.filename);\n  }\n  // Your SQLite code here.\n};\n\nlog('Loading and initializing SQLite3 module...');\nsqlite3InitModule({\n  print: log,\n  printErr: error,\n}).then((sqlite3) =\u003e {\n  log('Done initializing. Running demo...');\n  try {\n    start(sqlite3);\n  } catch (err) {\n    error(err.name, err.message);\n  }\n});\n```\n\nThe `db` object above implements the\n[Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).\n\n### In the main thread (without OPFS):\n\n```js\nimport sqlite3InitModule from '@sqlite.org/sqlite-wasm';\n\nconst log = (...args) =\u003e console.log(...args);\nconst error = (...args) =\u003e console.error(...args);\n\nconst start = function (sqlite3) {\n  log('Running SQLite3 version', sqlite3.version.libVersion);\n  const db = new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');\n  // Your SQLite code here.\n};\n\nlog('Loading and initializing SQLite3 module...');\nsqlite3InitModule({\n  print: log,\n  printErr: error,\n}).then((sqlite3) =\u003e {\n  try {\n    log('Done initializing. Running demo...');\n    start(sqlite3);\n  } catch (err) {\n    error(err.name, err.message);\n  }\n});\n```\n\nThe `db` object above implements the\n[Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).\n\n## Usage with vite\n\nIf you are using [vite](https://vitejs.dev/), you need to add the following\nconfig option in `vite.config.js`:\n\n```js\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n  server: {\n    headers: {\n      'Cross-Origin-Opener-Policy': 'same-origin',\n      'Cross-Origin-Embedder-Policy': 'require-corp',\n    },\n  },\n  optimizeDeps: {\n    exclude: ['@sqlite.org/sqlite-wasm'],\n  },\n});\n```\n\nCheck out a\n[sample project](https://stackblitz.com/edit/vitejs-vite-ttrbwh?file=main.js)\nthat shows this in action.\n\n## Demo\n\nSee the [demo](https://github.com/sqlite/sqlite-wasm/tree/main/demo) folder for\nexamples of how to use this in the main thread and in a worker. (Note that the\nworker variant requires special HTTP headers, so it can't be hosted on GitHub\nPages.) An example that shows how to use this with vite is available on\n[StackBlitz](https://stackblitz.com/edit/vitejs-vite-ttrbwh?file=main.js).\n\n## Projects using this package\n\nSee the list of\n[npm dependents](https://www.npmjs.com/browse/depended/@sqlite.org/sqlite-wasm)\nfor this package.\n\n## Deploying a new version\n\n(These steps can only be executed by maintainers.)\n\n1. Update the version number in `package.json` reflecting the current\n   [SQLite version number](https://sqlite.org/download.html) and add a build\n   identifier suffix like `-build1`. The complete version number should read\n   something like `3.41.2-build1`.\n1. Run `npm run build` to build the ES Module. This downloads the latest SQLite\n   Wasm binary and builds the ES Module.\n1. Run `npm run deploy` to commit the changes, push to GitHub, and publish the\n   new version to npm.\n\n## License\n\nApache 2.0.\n\n## Acknowledgements\n\nThis project is based on [SQLite Wasm](https://sqlite.org/wasm), which it\nconveniently wraps as an ES Module and publishes to npm as\n[`@sqlite.org/sqlite-wasm`](https://www.npmjs.com/package/@sqlite.org/sqlite-wasm).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftursodatabase%2Flibsql-wasm-experimental","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftursodatabase%2Flibsql-wasm-experimental","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftursodatabase%2Flibsql-wasm-experimental/lists"}