{"id":30535296,"url":"https://github.com/powersync-ja/drizzle-driver-sync","last_synced_at":"2025-08-27T14:53:23.758Z","repository":{"id":311798512,"uuid":"1045065472","full_name":"powersync-ja/drizzle-driver-sync","owner":"powersync-ja","description":"Synchronous drizzle driver for op-sqlite","archived":false,"fork":false,"pushed_at":"2025-08-26T16:53:30.000Z","size":114,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-26T23:28:26.114Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/powersync-ja.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2025-08-26T15:51:19.000Z","updated_at":"2025-08-26T16:53:34.000Z","dependencies_parsed_at":"2025-08-26T23:30:39.445Z","dependency_job_id":"2e5edbb7-8ed1-409f-89aa-eaeaf486a23a","html_url":"https://github.com/powersync-ja/drizzle-driver-sync","commit_stats":null,"previous_names":["powersync-ja/drizzle-driver-sync"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/powersync-ja/drizzle-driver-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fdrizzle-driver-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fdrizzle-driver-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fdrizzle-driver-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fdrizzle-driver-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/powersync-ja","download_url":"https://codeload.github.com/powersync-ja/drizzle-driver-sync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fdrizzle-driver-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272341515,"owners_count":24917503,"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","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08-27T14:53:19.760Z","updated_at":"2025-08-27T14:53:23.752Z","avatar_url":"https://github.com/powersync-ja.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PowerSync Drizzle Driver\n\nThis package (`@powersync/drizzle-driver-sync`) brings the benefits of an ORM through our maintained [Drizzle](https://orm.drizzle.team/) driver to PowerSync.\n\n## Alpha Release\n\nThe `drizzle-driver-sync` package is currently in an Alpha release.\n\n**Only query support is available at this time.** Support for inserts, updates, and deletes will be added in a future release.\n\n\n## Getting Started\n\nSet up the PowerSync Database and wrap it with Drizzle.\n\n```js\nimport { wrapPowerSyncWithDrizzle } from '@powersync/drizzle-driver-sync';\nimport { PowerSyncDatabase } from '@powersync/web';\nimport { relations } from 'drizzle-orm';\nimport { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';\nimport { AppSchema } from './schema';\n\nexport const lists = sqliteTable('lists', {\n  id: text('id'),\n  name: text('name')\n});\n\nexport const todos = sqliteTable('todos', {\n  id: text('id'),\n  description: text('description'),\n  list_id: text('list_id'),\n  created_at: text('created_at')\n});\n\nexport const listsRelations = relations(lists, ({ one, many }) =\u003e ({\n  todos: many(todos)\n}));\n\nexport const todosRelations = relations(todos, ({ one, many }) =\u003e ({\n  list: one(lists, {\n    fields: [todos.list_id],\n    references: [lists.id]\n  })\n}));\n\nexport const drizzleSchema = {\n  lists,\n  todos,\n  listsRelations,\n  todosRelations\n};\n\n// As an alternative to manually defining a PowerSync schema, generate the local PowerSync schema from the Drizzle schema with the `DrizzleAppSchema` constructor:\n// import { DrizzleAppSchema } from '@powersync/drizzle-driver-sync';\n// export const AppSchema = new DrizzleAppSchema(drizzleSchema);\n//\n// This is optional, but recommended, since you will only need to maintain one schema on the client-side\n// Read on to learn more.\n\nexport const powerSyncDb = new PowerSyncDatabase({\n  database: {\n    dbFilename: 'test.sqlite'\n  },\n  schema: AppSchema\n});\n\n// This is the DB you will use in queries\nexport const db = wrapPowerSyncWithDrizzle(powerSyncDb, {\n  schema: drizzleSchema\n});\n```\n\n## Schema Conversion\n\nThe `DrizzleAppSchema` constructor simplifies the process of integrating Drizzle with PowerSync. It infers the local [PowerSync schema](https://docs.powersync.com/installation/client-side-setup/define-your-schema) from your Drizzle schema definition, providing a unified development experience.\n\nAs the PowerSync schema only supports SQLite types (`text`, `integer`, and `real`), the same limitation extends to the Drizzle table definitions.\n\nTo use it, define your Drizzle tables and supply the schema to the `DrizzleAppSchema` function:\n\n```js\nimport { DrizzleAppSchema } from '@powersync/drizzle-driver-sync';\nimport { sqliteTable, text } from 'drizzle-orm/sqlite-core';\n\n// Define a Drizzle table\nconst lists = sqliteTable('lists', {\n  id: text('id').primaryKey().notNull(),\n  created_at: text('created_at'),\n  name: text('name').notNull(),\n  owner_id: text('owner_id')\n});\n\nexport const drizzleSchema = {\n  lists\n};\n\n// Infer the PowerSync schema from your Drizzle schema\nexport const AppSchema = new DrizzleAppSchema(drizzleSchema);\n```\n\n### Defining PowerSync Options\n\nThe PowerSync table definition allows additional options supported by PowerSync's app schema beyond that which are supported by Drizzle.\nThey can be specified as follows. Note that these options exclude indexes as they can be specified in a Drizzle table.\n\n```js\nimport { DrizzleAppSchema } from '@powersync/drizzle-driver-sync';\n// import { DrizzleAppSchema, type DrizzleTableWithPowerSyncOptions} from '@powersync/drizzle-driver'; for TypeScript\n\nconst listsWithOptions = { tableDefinition: logs, options: { localOnly: true } };\n// const listsWithOptions: DrizzleTableWithPowerSyncOptions = { tableDefinition: logs, options: { localOnly: true } }; for TypeScript\n\nexport const drizzleSchemaWithOptions = {\n  lists: listsWithOptions\n};\n\nexport const AppSchema = new DrizzleAppSchema(drizzleSchemaWithOptions);\n```\n\n### Converting a Single Table From Drizzle to PowerSync\n\nDrizzle tables can also be converted on a table-by-table basis with `toPowerSyncTable`.\n\n```js\nimport { toPowerSyncTable } from '@powersync/drizzle-driver-sync';\nimport { Schema } from '@powersync/web';\nimport { sqliteTable, text } from 'drizzle-orm/sqlite-core';\n\n// Define a Drizzle table\nconst lists = sqliteTable('lists', {\n  id: text('id').primaryKey().notNull(),\n  created_at: text('created_at'),\n  name: text('name').notNull(),\n  owner_id: text('owner_id')\n});\n\nconst psLists = toPowerSyncTable(lists); // converts the Drizzle table to a PowerSync table\n// toPowerSyncTable(lists, { localOnly: true }); - allows for PowerSync table configuration\n\nexport const AppSchema = new Schema({\n  lists: psLists // names the table `lists` in the PowerSync schema\n});\n```\n\n## Compilable queries\n\nTo use Drizzle queries in your hooks and composables, queries need to be converted using `toCompilableQuery`.\n\n```js\nimport { toCompilableQuery } from '@powersync/drizzle-driver-sync';\n\nconst query = db.select().from(lists);\nconst { data: listRecords, isLoading } = useQuery(toCompilableQuery(query));\n```\n\nFor more information on how to use Drizzle queries in PowerSync, see [here](https://docs.powersync.com/client-sdk-references/javascript-web/javascript-orm/drizzle#usage-examples).\n\n## Known limitations\n\n- The integration does not currently support nested transactions (also known as `savepoints`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowersync-ja%2Fdrizzle-driver-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowersync-ja%2Fdrizzle-driver-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowersync-ja%2Fdrizzle-driver-sync/lists"}