{"id":28146309,"url":"https://github.com/Sheraff/drizzle-orm-crsqlite-wasm","last_synced_at":"2025-05-14T23:12:38.309Z","repository":{"id":230586056,"uuid":"779747326","full_name":"Sheraff/drizzle-orm-crsqlite-wasm","owner":"Sheraff","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-01T18:48:39.000Z","size":20,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T10:12:45.018Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/drizzle-orm-crsqlite-wasm","language":"TypeScript","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/Sheraff.png","metadata":{"files":{"readme":"README.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,"zenodo":null}},"created_at":"2024-03-30T17:09:00.000Z","updated_at":"2025-03-30T03:06:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"6356db42-f572-48c2-b9b5-0fcf08632e41","html_url":"https://github.com/Sheraff/drizzle-orm-crsqlite-wasm","commit_stats":null,"previous_names":["sheraff/drizzle-orm-crsqlite-wasm"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sheraff%2Fdrizzle-orm-crsqlite-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sheraff%2Fdrizzle-orm-crsqlite-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sheraff%2Fdrizzle-orm-crsqlite-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sheraff%2Fdrizzle-orm-crsqlite-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sheraff","download_url":"https://codeload.github.com/Sheraff/drizzle-orm-crsqlite-wasm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243318,"owners_count":22038046,"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":[],"created_at":"2025-05-14T23:12:27.244Z","updated_at":"2025-05-14T23:12:38.294Z","avatar_url":"https://github.com/Sheraff.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003e [!TIP]\n\u003e The goal of this package is to get merged into the official `drizzle-orm` package. In the meantime it provides a way to use `crsqlite-wasm` as the underlying database engine for `drizzle`.\n\n# What is this?\n\nThis package is an adapter for `drizzle` to use `crsqlite-wasm` as the underlying database engine. It is meant to work in the browser (uses web crypto for hashing). It is similar to the other adapters you might find in the official `drizzle-orm` package (like `drizzle-orm/libsql` or `drizzle-orm/better-sqlite3`).\n\n# Quick start\n\n```shell\nnpm i drizzle-orm-crsqlite-wasm\n```\n\n```ts\nimport { initWasm } from \"@vlcn.io/crsqlite-wasm\"\nimport * as schema from \"my-regular-drizzle-schema.ts\"\nimport { drizzle } from \"drizzle-orm-crsqlite-wasm\"\n\nconst sqlite = await initWasm()\nconst sql = await sqlite.open(\"test\")\nconst db = drizzle(sql)\nconst countries = await db.select().from(schema.countries).all()\n```\n\n# How to use it?\n\n1. export all migrations from the drizzle migrations folder (following example uses `Vite`)\n\n   ```ts\n   // \u003cdrizzle-migrations\u003e/index.ts\n   export const migrations = Object.fromEntries(\n   \tObject.entries(\n   \t\timport.meta.glob(\"./*.sql\", {\n   \t\t\teager: true,\n   \t\t\tquery: \"?raw\",\n   \t\t\timport: \"default\",\n   \t\t})\n   \t).map(([key, value]) =\u003e [key.slice(2, -4), value])\n   )\n   ```\n\n2. create browser equivalent of node's `crypto.createHash(\"sha256\")`\n\n   ```ts\n   // \u003cdrizzle-migrations\u003e/hash.ts\n   async function createSha256Hash(query: string) {\n   \tconst encoder = new TextEncoder()\n   \tconst data = encoder.encode(query)\n   \tconst hash = await globalThis.crypto.subtle.digest(\"SHA-256\", data)\n   \tconst hashArray = Array.from(new Uint8Array(hash))\n   \tconst hashHex = hashArray\n   \t\t.map((b) =\u003e b.toString(16).padStart(2, \"0\"))\n   \t\t.join(\"\")\n   \treturn hashHex\n   }\n   ```\n\n3. process all migration data into a format useable by `drizzle`\n\n   ```ts\n   import migrationJournal from \"\u003cdrizzle-migrations\u003e/meta/_journal.json\"\n   import { migrations } from \"\u003cdrizzle-migrations\u003e/index.ts\"\n   import { createSha256Hash } from \"\u003cdrizzle-migrations\u003e/hash.ts\"\n\n   function getMigrations() {\n   \tconst journal = migrationJournal as {\n   \t\tentries: Array\u003c{\n   \t\t\tidx: number\n   \t\t\twhen: number\n   \t\t\ttag: string\n   \t\t\tbreakpoints: boolean\n   \t\t}\u003e\n   \t}\n   \tconst migrationQueries: MigrationMeta[] = []\n   \tfor (const journalEntry of journal.entries) {\n   \t\tconst query = migrations[journalEntry.tag as keyof typeof migrations]\n   \t\tconst result = query.split(\"--\u003e statement-breakpoint\")\n   \t\tmigrationQueries.push({\n   \t\t\tsql: result,\n   \t\t\tbps: journalEntry.breakpoints,\n   \t\t\tfolderMillis: journalEntry.when,\n   \t\t\thash: await createSha256Hash(query),\n   \t\t})\n   \t}\n   \treturn migrationQueries\n   }\n   ```\n\n4. create a `drizzle` instance and run the migrations\n\n   ```ts\n   import { initWasm } from \"@vlcn.io/crsqlite-wasm\"\n   import * as schema from \"my-regular-drizzle-schema.ts\"\n   import { drizzle } from \"drizzle-orm-crsqlite-wasm\"\n   import { migrate } from \"drizzle-orm-crsqlite-wasm/migrator\"\n\n   const sqlite = await initWasm()\n   const sql = await sqlite.open()\n   const db = drizzle(sql, { schema, logger: true })\n   await migrate(db, { migrations: await getMigrations() })\n   ```\n\n5. use as a regular `drizzle` instance\n\n   ```ts\n   const [country] = await db\n   \t.select()\n   \t.from(schema.countries)\n   \t.where(eq(schema.countries.name, \"Peru\"))\n   ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSheraff%2Fdrizzle-orm-crsqlite-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSheraff%2Fdrizzle-orm-crsqlite-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSheraff%2Fdrizzle-orm-crsqlite-wasm/lists"}