{"_id":"kysely-pglite","_rev":"5-847777c89c040e21ca41582c519d77fd","name":"kysely-pglite","dist-tags":{"latest":"0.6.1"},"versions":{"0.3.0":{"name":"kysely-pglite","version":"0.3.0","keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"author":{"name":"Daniel Sandiego"},"_id":"kysely-pglite@0.3.0","maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"dist":{"shasum":"ad001fd611e7210fcc9076062311ef3d8c9855ca","tarball":"https://registry.npmjs.org/kysely-pglite/-/kysely-pglite-0.3.0.tgz","fileCount":8,"integrity":"sha512-EvM6FyGWAyiU5nwkuBWKPI8IiYJwnL96+TUqdHsTtl3p1qF5fjr7Z8svPeYQy6CjgovEPLOdlIdCx8hX7TSX3g==","signatures":[{"sig":"MEQCIEdNZZOBgqFvVw5wU9u+BmK2G7Fj3KYbu0hwEZWlbnsCAiADAIgR8w5sxJJPFTL88A3EfC4zDSfd1Mvg/JsJU4s6Pg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21870},"main":"./dist/index.cjs","type":"module","_from":"file:kysely-pglite-0.3.0.tgz","types":"./dist/index.d.cts","module":"./dist/index.mjs","exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"scripts":{"test":"vitest","build":"pkgroll --clean-dist --sourcemap","format":"prettier ./src --write"},"_npmUser":{"name":"dnlsand","email":"dnlsandiego@gmail.com"},"_resolved":"/private/var/folders/l1/76swhhs54yn7n6ptb0784hf40000gn/T/db906b2ffd5ee0a36c6235df3e8ee32b/kysely-pglite-0.3.0.tgz","_integrity":"sha512-EvM6FyGWAyiU5nwkuBWKPI8IiYJwnL96+TUqdHsTtl3p1qF5fjr7Z8svPeYQy6CjgovEPLOdlIdCx8hX7TSX3g==","repository":{"url":"git+https://github.com/dnlsandiego/kysely-pglite.git","type":"git"},"_npmVersion":"9.8.1","description":"Kysely dialect for @electric-sql/pglite","directories":{},"_nodeVersion":"20.6.1","_hasShrinkwrap":false,"packageManager":"pnpm@8.14.2","devDependencies":{"kysely":"^0.27.4","vitest":"^2.0.3","pkgroll":"^2.1.1","prettier":"^3.3.3","typescript":"^5.0.0","@electric-sql/pglite":"^0.2.0"},"peerDependencies":{"kysely":"*","@electric-sql/pglite":"*"},"_npmOperationalInternal":{"tmp":"tmp/kysely-pglite_0.3.0_1723564906154_0.6338170207757627","host":"s3://npm-registry-packages"}},"0.4.0":{"name":"kysely-pglite","version":"0.4.0","keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"author":{"name":"Daniel Sandiego"},"_id":"kysely-pglite@0.4.0","maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"dist":{"shasum":"c9770599de7dead457cf0ad150b1e8ebea3b00ba","tarball":"https://registry.npmjs.org/kysely-pglite/-/kysely-pglite-0.4.0.tgz","fileCount":8,"integrity":"sha512-ugdX3fjCqVA8mRDKbLQFCWxd5wSi68hZEuugb0DuQHNaqZZI55UV9FhQPlBenJgGEIYG1QiICNM2/2CSuVeC/Q==","signatures":[{"sig":"MEUCIQCbwUudX26AkYFw4n29KOpzrpah9g4Xv7O5SEvYvlBxpwIgFehFIWinpXHZ1sXm9cJkoAFryl36LdG9zulhsxdeeH4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21870},"main":"./dist/index.cjs","type":"module","_from":"file:kysely-pglite-0.4.0.tgz","types":"./dist/index.d.cts","module":"./dist/index.mjs","exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"scripts":{"test":"vitest","build":"pkgroll --clean-dist --sourcemap","format":"prettier ./src --write"},"_npmUser":{"name":"dnlsand","email":"dnlsandiego@gmail.com"},"_resolved":"/private/var/folders/l1/76swhhs54yn7n6ptb0784hf40000gn/T/eb4bf96ca4b3ffbbabee24a24c847c17/kysely-pglite-0.4.0.tgz","_integrity":"sha512-ugdX3fjCqVA8mRDKbLQFCWxd5wSi68hZEuugb0DuQHNaqZZI55UV9FhQPlBenJgGEIYG1QiICNM2/2CSuVeC/Q==","repository":{"url":"git+https://github.com/dnlsandiego/kysely-pglite.git","type":"git"},"_npmVersion":"9.8.1","description":"Kysely dialect for @electric-sql/pglite","directories":{},"_nodeVersion":"20.6.1","_hasShrinkwrap":false,"packageManager":"pnpm@8.14.2","devDependencies":{"kysely":"^0.27.4","vitest":"^2.0.3","pkgroll":"^2.1.1","prettier":"^3.3.3","typescript":"^5.0.0","@electric-sql/pglite":"^0.2.0"},"peerDependencies":{"kysely":"*","@electric-sql/pglite":"*"},"_npmOperationalInternal":{"tmp":"tmp/kysely-pglite_0.4.0_1723566081031_0.10977616677849134","host":"s3://npm-registry-packages"}},"0.4.1":{"name":"kysely-pglite","version":"0.4.1","keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"author":{"name":"Daniel Sandiego"},"license":"MIT","_id":"kysely-pglite@0.4.1","maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"dist":{"shasum":"a60e542c0555eada28e5da636c1ec654d8bb48db","tarball":"https://registry.npmjs.org/kysely-pglite/-/kysely-pglite-0.4.1.tgz","fileCount":9,"integrity":"sha512-5LBGrpan18iUi6MBHlTQBeKljjm6uqeDHf4fPdNp84ZbSdoKjgI2J8v9j++b5hsfdMoeQ+WVAsmWpbBVICmtdA==","signatures":[{"sig":"MEYCIQCRqUo1mSzpEtwuUXSem1V55n8lftDPZXvSIavmm1C67wIhAIsxUWhamMYTY80B2+fxjmu1lNe/KbgO2c3MpC4ULM2d","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23059},"main":"./dist/index.cjs","type":"module","_from":"file:kysely-pglite-0.4.1.tgz","types":"./dist/index.d.cts","module":"./dist/index.mjs","exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"scripts":{"test":"vitest","build":"pkgroll --clean-dist --sourcemap","format":"prettier ./src --write"},"_npmUser":{"name":"dnlsand","email":"dnlsandiego@gmail.com"},"_resolved":"/private/var/folders/l1/76swhhs54yn7n6ptb0784hf40000gn/T/44df6439bef74d7bf1e8f849b60dc73f/kysely-pglite-0.4.1.tgz","_integrity":"sha512-5LBGrpan18iUi6MBHlTQBeKljjm6uqeDHf4fPdNp84ZbSdoKjgI2J8v9j++b5hsfdMoeQ+WVAsmWpbBVICmtdA==","repository":{"url":"git+https://github.com/dnlsandiego/kysely-pglite.git","type":"git"},"_npmVersion":"9.8.1","description":"Kysely dialect for @electric-sql/pglite","directories":{},"_nodeVersion":"20.6.1","_hasShrinkwrap":false,"packageManager":"pnpm@8.14.2","devDependencies":{"kysely":"^0.27.4","vitest":"^2.0.3","pkgroll":"^2.1.1","prettier":"^3.3.3","typescript":"^5.0.0","@electric-sql/pglite":"^0.2.0"},"peerDependencies":{"kysely":"*","@electric-sql/pglite":"*"},"_npmOperationalInternal":{"tmp":"tmp/kysely-pglite_0.4.1_1723567843064_0.6608170321137459","host":"s3://npm-registry-packages"}},"0.5.0":{"name":"kysely-pglite","version":"0.5.0","keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"author":{"name":"Daniel Sandiego"},"license":"MIT","_id":"kysely-pglite@0.5.0","maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"dist":{"shasum":"05bd3df5b6b736578415e4ab354a830083a20a0a","tarball":"https://registry.npmjs.org/kysely-pglite/-/kysely-pglite-0.5.0.tgz","fileCount":9,"integrity":"sha512-jK5qfkQPmUl3LAdLZg1+aBwGSsO83+MxkkrKVTA17kL13/zKmRNmQGs+pVvSjWTrmVLdU22L5U+hR8b8WfROLw==","signatures":[{"sig":"MEUCIQDPAx+IRTeVu3Kyrn/LTNQOVUqxlzCf9EJsI6rhE0bAKwIgNqyE3dM0GpgNMzmlxmsrYc45O09qfJpedboA2zBdAVQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23907},"main":"./dist/index.cjs","type":"module","_from":"file:kysely-pglite-0.5.0.tgz","types":"./dist/index.d.cts","module":"./dist/index.mjs","exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"scripts":{"test":"vitest","build":"pkgroll --clean-dist --sourcemap","format":"prettier ./src --write"},"_npmUser":{"name":"dnlsand","email":"dnlsandiego@gmail.com"},"_resolved":"/private/var/folders/l1/76swhhs54yn7n6ptb0784hf40000gn/T/29d48d1e5859ad1aff21dd7e66e0ad9c/kysely-pglite-0.5.0.tgz","_integrity":"sha512-jK5qfkQPmUl3LAdLZg1+aBwGSsO83+MxkkrKVTA17kL13/zKmRNmQGs+pVvSjWTrmVLdU22L5U+hR8b8WfROLw==","repository":{"url":"git+https://github.com/dnlsandiego/kysely-pglite.git","type":"git"},"_npmVersion":"9.8.1","description":"Kysely dialect for @electric-sql/pglite","directories":{},"_nodeVersion":"20.6.1","_hasShrinkwrap":false,"packageManager":"pnpm@8.14.2","devDependencies":{"kysely":"^0.27.4","vitest":"^2.0.3","pkgroll":"^2.1.1","prettier":"^3.3.3","typescript":"^5.0.0","@electric-sql/pglite":"^0.2.0"},"peerDependencies":{"kysely":"*","@electric-sql/pglite":"*"},"_npmOperationalInternal":{"tmp":"tmp/kysely-pglite_0.5.0_1723710944179_0.32093629837969817","host":"s3://npm-registry-packages"}},"0.6.0":{"name":"kysely-pglite","version":"0.6.0","keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"author":{"name":"Daniel Sandiego"},"license":"MIT","_id":"kysely-pglite@0.6.0","maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"bin":{"kpg":"bin/run.js","kysely-pglite":"bin/run.js"},"dist":{"shasum":"ca2855213723d9deee870661974341c1a66b15ca","tarball":"https://registry.npmjs.org/kysely-pglite/-/kysely-pglite-0.6.0.tgz","fileCount":50,"integrity":"sha512-WZ5JLv1U0zhpGTsTOjL7TluvMekXvJ0l3XHst6/7CLr4XyJqIldkbQyfKtDgT8WPxLt7hQYfCK1fuep7RfQEwA==","signatures":[{"sig":"MEQCIHurdLQTf1NpI9XijjK6pj3mdmhkvIFL8Uy8XHWTvYeTAiAJXZelbNKZsMi5uLtxVB2V1G2tRiULs3mdyT7DFu0cQA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":55129},"type":"module","_from":"file:kysely-pglite-0.6.0.tgz","oclif":{"dirname":"kysely-pglite","commands":{"target":"./dist/cli.js","strategy":"single"},"binAliases":["kysely-pglite","kpg"],"topicSeparator":" "},"types":"./dist/index.d.ts","module":"./dist/index.js","exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"imports":{"#*":{"default":"./dist/*"}},"scripts":{"dev":"tsc --watch","test":"vitest","build":"rimraf dist && tsc","format":"prettier ./src --write","typecheck":"tsc --noEmit"},"_npmUser":{"name":"dnlsand","email":"dnlsandiego@gmail.com"},"_resolved":"/private/var/folders/l1/76swhhs54yn7n6ptb0784hf40000gn/T/afdf1d8195bd6ad7874f9ba728bc8d82/kysely-pglite-0.6.0.tgz","_integrity":"sha512-WZ5JLv1U0zhpGTsTOjL7TluvMekXvJ0l3XHst6/7CLr4XyJqIldkbQyfKtDgT8WPxLt7hQYfCK1fuep7RfQEwA==","repository":{"url":"git+https://github.com/dnlsandiego/kysely-pglite.git","type":"git"},"_npmVersion":"9.8.1","description":"Kysely dialect for @electric-sql/pglite","directories":{},"_nodeVersion":"20.6.1","dependencies":{"jiti":"2.0.0-beta.3","globby":"^14.0.2","radash":"^12.1.0","consola":"^3.2.3","chokidar":"^3.6.0","fs-extra":"^11.2.0","@oclif/core":"^4.0.19","kysely-codegen":"^0.15.0","@sindresorhus/is":"^7.0.0","@repeaterjs/repeater":"^3.0.6"},"_hasShrinkwrap":false,"packageManager":"pnpm@8.14.2","devDependencies":{"tsx":"^4.19.0","rimraf":"^6.0.1","vitest":"^2.0.5","prettier":"^3.3.3","type-fest":"^4.25.0","typescript":"^5.5.4","@types/node":"^22.5.0","@types/fs-extra":"^11.0.4"},"peerDependencies":{"kysely":"*","@electric-sql/pglite":"*"},"_npmOperationalInternal":{"tmp":"tmp/kysely-pglite_0.6.0_1725285131152_0.33847216244276734","host":"s3://npm-registry-packages"}},"0.6.1":{"name":"kysely-pglite","version":"0.6.1","description":"Kysely dialect for @electric-sql/pglite","repository":{"type":"git","url":"git+https://github.com/dnlsandiego/kysely-pglite.git"},"keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"license":"MIT","type":"module","module":"./dist/index.js","types":"./dist/index.d.ts","packageManager":"pnpm@8.14.2","imports":{"#*":{"default":"./dist/*"}},"exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"peerDependencies":{"@electric-sql/pglite":"*","kysely":"*"},"devDependencies":{"@types/fs-extra":"^11.0.4","@types/node":"^22.5.0","prettier":"^3.3.3","rimraf":"^6.0.1","tsx":"^4.19.0","type-fest":"^4.25.0","typescript":"^5.5.4","vitest":"^2.0.5"},"dependencies":{"@oclif/core":"^4.0.19","@repeaterjs/repeater":"^3.0.6","@sindresorhus/is":"^7.0.0","chokidar":"^3.6.0","consola":"^3.2.3","fs-extra":"^11.2.0","globby":"^14.0.2","jiti":"2.0.0-beta.3","kysely-codegen":"^0.15.0","radash":"^12.1.0"},"bin":{"kysely-pglite":"bin/run.js","kpg":"bin/run.js"},"oclif":{"binAliases":["kysely-pglite","kpg"],"commands":{"strategy":"single","target":"./dist/cli.js"},"dirname":"kysely-pglite","topicSeparator":" "},"author":{"name":"Daniel Sandiego"},"scripts":{"build":"rimraf dist && tsc","dev":"tsc --watch","typecheck":"tsc --noEmit","format":"prettier ./src --write","test":"vitest"},"bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","_id":"kysely-pglite@0.6.1","_integrity":"sha512-+q9FS6km6Y9yLLxe4SAMu4cQA3qIOSqdZ9uidVDU7g90Z/ZEjDhEKX/Rk5xug0HoGpCfMLHC2XGLqiVMZXqnRw==","_resolved":"/private/var/folders/l1/76swhhs54yn7n6ptb0784hf40000gn/T/224985cb41a3c75988c1b7b2bb00190f/kysely-pglite-0.6.1.tgz","_from":"file:kysely-pglite-0.6.1.tgz","_nodeVersion":"20.6.1","_npmVersion":"9.8.1","dist":{"integrity":"sha512-+q9FS6km6Y9yLLxe4SAMu4cQA3qIOSqdZ9uidVDU7g90Z/ZEjDhEKX/Rk5xug0HoGpCfMLHC2XGLqiVMZXqnRw==","shasum":"decbc1afbca20d521ddacd7363428abe53349fcb","tarball":"https://registry.npmjs.org/kysely-pglite/-/kysely-pglite-0.6.1.tgz","fileCount":50,"unpackedSize":55152,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICXLCi8HtDmn3D9dec1Ib6dzh4DsF0pGXV8Daws1hbbKAiEA8j7bg/ptgMG6JM0U16FCjtfB4dIRF4UlZCXmWq34zXU="}]},"_npmUser":{"name":"dnlsand","email":"dnlsandiego@gmail.com"},"directories":{},"maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/kysely-pglite_0.6.1_1726478384670_0.43710207229927933"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-13T16:01:46.153Z","modified":"2024-09-16T09:19:45.053Z","0.3.0":"2024-08-13T16:01:46.332Z","0.4.0":"2024-08-13T16:21:21.171Z","0.4.1":"2024-08-13T16:50:43.217Z","0.5.0":"2024-08-15T08:35:44.361Z","0.6.0":"2024-09-02T13:52:11.286Z","0.6.1":"2024-09-16T09:19:44.867Z"},"bugs":{"url":"https://github.com/dnlsandiego/kysely-pglite/issues"},"author":{"name":"Daniel Sandiego"},"license":"MIT","homepage":"https://github.com/dnlsandiego/kysely-pglite#readme","keywords":["@electric-sql/pglite","kysely","postgresql","wasm","database","sql"],"repository":{"type":"git","url":"git+https://github.com/dnlsandiego/kysely-pglite.git"},"description":"Kysely dialect for @electric-sql/pglite","maintainers":[{"name":"dnlsand","email":"dnlsandiego@gmail.com"}],"readme":"# kysely-pglite\n\n[Kysely](https://github.com/kysely-org/kysely) dialect for [PGlite](https://github.com/electric-sql/pglite) with a [CLI](#generating-types) to generate TypeScript types.\n\nPGlite's [Live Queries](https://pglite.dev/docs/live-queries) extension can also be integrated with Kysely to take advantage of its type-safe features when writing queries to watch through a [AsyncIterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator) based class [`KyselyLive`](#kyselylive-usage).\n\n## Installation\n\n[`@electric-sql/pglite`](https://github.com/electric-sql/pglite) needs to be installed as well.\n\n#### PNPM\n\n```bash\npnpm add @electric-sql/pglite kysely-pglite\n```\n\n#### NPM\n\n```bash\nnpm install @electric-sql/pglite kysely-pglite\n```\n\n## Usage\n\nThe examples below mostly use the static async method `await KyselyPGlite.create()` to align with the [PGlite docs](https://pglite.dev/docs/api#main-constructor). But an instance can still be created using the `new KyselyPGlite()` constructor.\n\n```typescript\nimport { Kysely } from 'kysely'\nimport { KyselyPGlite } from 'kysely-pglite'\n\n// Use in-memory Postgres\nconst { dialect } = await KyselyPGlite.create()\n\n// For persisting the data to disk, pass in a path to a directory\n// const { dialect } = await KyselyPGlite.create('./path/to/pgdata')\n\nconst db = new Kysely<any>({ dialect })\n```\n\n`PGlite` options can be passed in, it has the same function signature as PGlite. See [PGlite options](https://pglite.dev/docs/api#options) for more info.\n\n```typescript\nconst { dialect } = await KyselyPGlite.create('./path/to/pgdata', {\n  debug: 3,\n  relaxedDurability: true,\n})\n```\n\n## Generating Types\n\n`kysely-pglite` has a CLI to generate TypeScript types. It's a wrapper around [kysely-codegen](https://github.com/RobinBlomberg/kysely-codegen) to get around its requirement of a connection to a running database. So the CLI accepts most of `kysely-codegen`'s options just minus the connection specific settings.\n\nThe codegen needs a file/directory of Kysely migrations or a persisted PGlite database to generate the types.\n\nUsing Kysely migrations, the `kysely-pglite` CLI expects a path to either a file or directory of migration files that exports 2 async functions called `up` and `down` (same pattern as in the [Kysely docs](https://kysely.dev/docs/migrations#migration-files)). For example:\n\nLet's say you have this project structure:\n\n```\nmy-project/\n├── .pgdata\n├── src/\n│   ├── db/\n│   │   ├── migrations/\n│   │   │   └── 1716743937856_create_user_table.ts\n│   │   ├── db.ts\n│   └── index.ts\n├── package.json\n```\n\n```typescript\n// src/db/migrations/1716743937856_create_user_table.ts\nimport { Kysely } from 'kysely'\n\nexport async function up(db: Kysely<any>) {\n  await db.schema\n    .createTable('user')\n    .addColumn('id', 'serial', (cb) => cb.primaryKey())\n    .addColumn('name', 'text', (cb) => cb.notNull())\n    .execute()\n}\n\nexport async function down(db: Kysely<any>) {\n  await db.schema.dropTable('user').execute()\n}\n```\n\nRun the codegen\n\n```bash\nnpx kysely-pglite ./src/db/migrations --outFile ./src/db/schema.ts\n```\n\nResulting structure\n\n```\nproject-root/\n├── .pgdata\n├── src/\n│   ├── db/\n│   │   ├── migrations/\n│   │   │   └── 1716743937856_create_user_table.ts\n│   │   ├── db.ts\n├── │   ├── schema.ts\n│   └── index.ts\n├── package.json\n```\n\n> [!TIP]\n> The CLI is also aliased as `kpg` for easier typing. So the above could be `npx kpg ./src/db/migrations -o ./src/db/types.ts`\n\nA persisted PGlite database can also be used to generate the types. `kysely-pglite` will automatically detect that the directory is a PGlite database and not migration files.\n\n```bash\nnpx kysely-pglite ./path/to/pgdata\n```\n\nThere's also a `--watch` option to make `kysely-pglite` watch the given `path` and re-generate the types whenever a change is detected.\n\n```bash\nnpx kysely-pglite --watch ./src/db/migrations --outFile ./src/db/schema.ts\n```\n\n## `KyselyLive`\n\n`KyselyLive` is a [AsyncIterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator) based wrapper for using PGlite's live queries extension with Kysely's type-safe features. To quickly compare:\n\n```typescript\nconst ret = pg.live.query(\n  'SELECT id, price FROM sales ORDER BY rand;',\n  [],\n  (res) => {\n    // res is the same as a standard query result object\n  },\n)\n\nconst pglive = new KyselyLive(pglite)\nconst query = db\n  .selectFrom('sales')\n  .select(['id', 'price'])\n  .orderBy((eb) => eb.fn('rand'))\n\nfor await (const data of pglive.query(query).subscribe) {\n  const [sale] = data\n  console.log(sale.id, sale.price)\n}\n```\n\nA little more fleshed out example:\n\n```typescript\nimport { live } from '@electric-sql/pglite/live'\nimport { KyselyPGlite, KyselyLive } from 'kysely-pglite'\n\ninterface User {\n  id: Generated<number>\n  name: string\n}\n\ninterface DB {\n  user: User\n}\n\n// Include the `live` extension when creating a KyselyPGlite instance. `client` here is the PGlite instance that the Dialect is using.\nconst { dialect, client } = new KyselyPGlite({ extensions: { live } })\n\nconst db = new Kysely<DB>({ dialect })\n\n// Now create a `KyselyLive` instance.\nconst pglive = new KyselyLive(client)\n\n// `KyselyLive`'s methods require a `SelectQueryBuilder` from your `db` to infer the type of the data your query subscription will emit.\nconst usersQuery = db.selectFrom('user').selectAll().orderBy('id asc')\nconst liveQuery = pglive.query(usersQuery)\n\n// subscribe to `user` table changes. `data` will be typed as `User[]`\nfor await (const data of liveQuery.subscribe) {\n  const [user] = data\n  console.log(user.id, user.name)\n}\n\n// To `unsubscribe` from the query:\nliveQuery.unsubscribe()\n\n// To manually refresh the query:\nliveQuery.refresh()\n```\n\n## Migrations\n\n#### In-Memory Usage\n\nIf you're using PGlite as an in-memory DB for a server for example, you'll most likely need to create its tables everytime the server starts up. Which means the migrations will also need to get applied on every server start up. `kysely-pglite` exports a `createMigrator` utility to create a [Kysely Migrator](https://kysely-org.github.io/kysely-apidoc/classes/Migrator.html) and provide it with your migrations when you run it. Example setup:\n\n```\nproject-root/\n├── src/\n│   ├── db/\n│   │   ├── migrations/\n│   │   │   └── 1716743937856_create_user_table.ts\n│   │   ├── db.ts\n├── │   ├── schema.ts\n│   ├── index.ts\n│   ├── server.ts\n├── package.json\n```\n\n```typescript\n// file: src/db/db.ts\nimport { Kysely, Migrator } from 'kysely'\nimport { KyselyPGlite, createMigrator } from 'kysely-pglite'\n\nconst { dialect } = await KyselyPGlite.create()\nexport const db = new Kysely({ dialect })\n\n// The 2nd parameter should be a path to a directory of migration files. Relative to the root dir\nexport const migrator = createMigrator(db, './src/db/migrations')\n```\n\n```typescript\n// file: src/server.ts\nimport { db, migrator } from './db/db.ts'\nimport express from 'express'\n\n// Run migrations before starting up the server\nawait migrator.migrateToLatest()\n\nconst app = express()\n\napp.listen(port, () => {\n  console.log(`Example app listening on port ${port}`)\n})\n```\n","readmeFilename":"README.md"}