{"id":22384732,"url":"https://github.com/dallashoff/sqlocal","last_synced_at":"2025-04-14T08:56:37.686Z","repository":{"id":178215150,"uuid":"661540297","full_name":"DallasHoff/sqlocal","owner":"DallasHoff","description":"SQLocal makes it easy to run SQLite3 in the browser, backed by the origin private file system.","archived":false,"fork":false,"pushed_at":"2024-10-24T03:24:29.000Z","size":657,"stargazers_count":364,"open_issues_count":2,"forks_count":16,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-24T15:58:47.978Z","etag":null,"topics":["local-first","opfs","sqlite","sqlite-wasm","typescript-library"],"latest_commit_sha":null,"homepage":"https://sqlocal.dallashoffman.com","language":"TypeScript","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/DallasHoff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-07-03T05:32:01.000Z","updated_at":"2024-10-24T15:25:59.000Z","dependencies_parsed_at":"2024-02-03T06:24:00.756Z","dependency_job_id":"8650e210-1213-4393-93bc-6b9bdc32abb2","html_url":"https://github.com/DallasHoff/sqlocal","commit_stats":null,"previous_names":["dallashoff/sqlocal"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DallasHoff%2Fsqlocal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DallasHoff%2Fsqlocal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DallasHoff%2Fsqlocal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DallasHoff%2Fsqlocal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DallasHoff","download_url":"https://codeload.github.com/DallasHoff/sqlocal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852112,"owners_count":21171839,"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":["local-first","opfs","sqlite","sqlite-wasm","typescript-library"],"created_at":"2024-12-05T01:19:01.402Z","updated_at":"2025-04-14T08:56:37.667Z","avatar_url":"https://github.com/DallasHoff.png","language":"TypeScript","funding_links":["https://www.paypal.com/biz/fund?id=U3ZNM2Q26WJY8"],"categories":[],"sub_categories":[],"readme":"# SQLocal\n\nSQLocal makes it easy to run SQLite3 in the browser, backed by the origin private file system. It wraps the [WebAssembly build of SQLite3](https://sqlite.org/wasm/doc/trunk/index.md) and gives you a simple interface to interact with databases running on device.\n\n[Documentation](https://sqlocal.dallashoffman.com) - [GitHub](https://github.com/DallasHoff/sqlocal) - [NPM](https://www.npmjs.com/package/sqlocal) - [Fund](https://www.paypal.com/biz/fund?id=U3ZNM2Q26WJY8)\n\n## Features\n\n- 🔎 Locally executes any query that SQLite3 supports\n- 🧵 Runs the SQLite engine in a web worker so queries do not block the main thread\n- 📂 Persists data to the origin private file system, which is optimized for fast file I/O\n- 🔒 Each user can have their own private database instance\n- 🚀 Simple API; just name your database and start running SQL queries\n- 🛠️ Works with Kysely and Drizzle ORM for making type-safe queries\n\n## Examples\n\n```javascript\nimport { SQLocal } from 'sqlocal';\n\n// Create a client with a name for the SQLite file to save in\n// the origin private file system\nconst { sql } = new SQLocal('database.sqlite3');\n\n// Use the \"sql\" tagged template to execute a SQL statement\n// against the SQLite database\nawait sql`CREATE TABLE groceries (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)`;\n\n// Execute a parameterized statement just by inserting \n// parameters in the SQL string\nconst items = ['bread', 'milk', 'rice'];\nfor (let item of items) {\n  await sql`INSERT INTO groceries (name) VALUES (${item})`;\n}\n\n// SELECT queries and queries with the RETURNING clause will\n// return the matched records as an array of objects\nconst data = await sql`SELECT * FROM groceries`;\nconsole.log(data);\n```\n\nLog:\n\n```javascript\n[\n  { id: 1, name: 'bread' },\n  { id: 2, name: 'milk' },\n  { id: 3, name: 'rice' }\n]\n```\n\nOr, you can use SQLocal as a driver for [Kysely](https://kysely.dev/) or [Drizzle ORM](https://orm.drizzle.team/) to make fully-typed queries.\n\n### Kysely\n\n```typescript\nimport { SQLocalKysely } from 'sqlocal/kysely';\nimport { Kysely, Generated } from 'kysely';\n\n// Initialize SQLocalKysely and pass the dialect to Kysely\nconst { dialect } = new SQLocalKysely('database.sqlite3');\nconst db = new Kysely\u003cDB\u003e({ dialect });\n\n// Define your schema \n// (passed to the Kysely generic above)\ntype DB = {\n  groceries: {\n    id: Generated\u003cnumber\u003e;\n    name: string;\n  };\n};\n\n// Make type-safe queries\nconst data = await db\n  .selectFrom('groceries')\n  .select('name')\n  .orderBy('name', 'asc')\n  .execute();\nconsole.log(data);\n```\n\nSee the Kysely documentation for [getting started](https://kysely.dev/docs/getting-started?dialect=sqlite).\n\n### Drizzle\n\n```typescript\nimport { SQLocalDrizzle } from 'sqlocal/drizzle';\nimport { drizzle } from 'drizzle-orm/sqlite-proxy';\nimport { sqliteTable, int, text } from 'drizzle-orm/sqlite-core';\n\n// Initialize SQLocalDrizzle and pass the driver to Drizzle\nconst { driver } = new SQLocalDrizzle('database.sqlite3');\nconst db = drizzle(driver);\n\n// Define your schema\nconst groceries = sqliteTable('groceries', {\n  id: int('id').primaryKey({ autoIncrement: true }),\n  name: text('name').notNull(),\n});\n\n// Make type-safe queries\nconst data = await db\n  .select({ name: groceries.name })\n  .from(groceries)\n  .orderBy(groceries.name)\n  .all();\nconsole.log(data);\n```\n\nSee the Drizzle ORM documentation for [declaring your schema](https://orm.drizzle.team/docs/sql-schema-declaration) and [making queries](https://orm.drizzle.team/docs/crud).\n\n## Install\n\nInstall the SQLocal package in your application using your package manager.\n\n```sh\nnpm install sqlocal\n# or...\nyarn add sqlocal\n# or...\npnpm install sqlocal\n```\n\n### Cross-Origin Isolation\n\nIn order to persist data to the origin private file system, this package relies on APIs that require cross-origin isolation, so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.\n\n```http\nCross-Origin-Embedder-Policy: require-corp\nCross-Origin-Opener-Policy: same-origin\n```\n\nIf your development server uses Vite, you can do this by adding the following to your Vite configuration.\n\n```javascript\nplugins: [\n  {\n    name: 'configure-response-headers',\n    configureServer: (server) =\u003e {\n      server.middlewares.use((_req, res, next) =\u003e {\n        res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');\n        res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');\n        next();\n      });\n    },\n  },\n],\n```\n\n### Vite Configuration\n\nVite currently has an issue that prevents it from loading web worker files correctly with the default configuration. If you use Vite, please add the below to your Vite configuration to fix this.\n\n```javascript\noptimizeDeps: {\n  exclude: ['sqlocal'],\n},\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdallashoff%2Fsqlocal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdallashoff%2Fsqlocal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdallashoff%2Fsqlocal/lists"}