docs: add PGlite support

Kysely's built-in PGliteDialect uses the same introspector as PostgreSQL, so KyselyTypegenPostgresDialect works with it as-is.
This commit is contained in:
theoludwig committed 2026-10-09 21:19:26 +02:00
1 parent ff16be6787
commit 63a44d30f1
5 files changed
+187 -2

No files matched your search

+25 -1
View File
@@ -16,7 +16,7 @@ Why `kysely-typegen` if there is already `kysely-codegen`? Comparison:
| **Dependencies** | 35 total | 0 (no runtime dependencies) |
| **Type** | CLI | Library/Programmatic Usage |
| **Code Size/Maintainability** | Heavy | Lightweight/Simple and straightforward (string manipulation instead of complex AST) |
| **Database Support** | PostgreSQL, MySQL, SQLite, MSSQL, LibSQL | PostgreSQL, MySQL, SQLite (**can be easily extended to more**) |
| **Database Support** | PostgreSQL, MySQL, SQLite, MSSQL, LibSQL | PostgreSQL, PGlite, MySQL, SQLite (**can be easily extended to more**) |
`kysely-typegen` is a **library** (not a CLI), which means you are in control of where and how to run it, and is designed to be **extensible**, easy to add support for more database dialects.
@@ -79,6 +79,30 @@ export const database = new Kysely<DB>({ dialect })
export const databaseTypegen = new KyselyTypegenPostgresDialect({ database })
```
#### PGlite
[PGlite](https://pglite.dev/) is PostgreSQL compiled to WebAssembly that runs in-process. Use Kysely's built-in [`PGliteDialect`](https://kysely-org.github.io/kysely-apidoc/classes/PGliteDialect.html) with `KyselyTypegenPostgresDialect`: PGlite is introspected exactly like PostgreSQL. Because `kysely-typegen` is a library, it can introspect the PGlite instance your application already uses, which a CLI cannot do.
```sh
npm install @electric-sql/pglite
```
```ts
// database.ts
import { PGlite } from "@electric-sql/pglite"
import { Kysely, PGliteDialect } from "kysely"
import { KyselyTypegenPostgresDialect } from "kysely-typegen/postgres"
import type { DB } from "./codegen.ts"
const dialect = new PGliteDialect({
pglite: new PGlite(process.env["DATABASE_PATH"] ?? "./pgdata"),
})
export const database = new Kysely<DB>({ dialect })
export const databaseTypegen = new KyselyTypegenPostgresDialect({ database })
```
#### MySQL
```sh