Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/docs/orm-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,57 @@ await db.select().from(...);
See the [Drizzle documentation](https://orm.drizzle.team/docs/connect-pglite)
for more details.

## Kysely

[Kysely](https://kysely.dev) is a **type-safe** TypeScript SQL query builder
with support for many databases, including PGlite. Features include:

- End-to-end type-safety and autocompletion
- Composable, predictable, escape-rich, fluent API.
- Cancellable, pluggable, hookable.
- Migrations and DDL builders too.
- Built-in PGlite dialect (since Kysely `0.29.0`)

To use Kysely with PGlite, install `kysely` (>= 0.29) alongside `@electric-sql/pglite`:

```bash
npm i @electric-sql/pglite kysely
```

Then create a Kysely instance using the built-in `PGliteDialect`:

```ts
import { PGlite } from '@electric-sql/pglite'
import { Kysely, PGliteDialect } from 'kysely'

// See https://kysely.dev/docs/generating-types
interface Database {
person: {
id: string
}
}

const db = new Kysely<Database>({
dialect: new PGliteDialect({
pglite: new PGlite(),
}),
})

const people = await db.selectFrom('person').selectAll().execute()
```

`pglite` can also be a function (sync or async), in which case the PGlite
instance is created lazily the first time a query runs:

```ts
new PGliteDialect({
pglite: () => new PGlite('./path/to/pgdata'),
})
```

See the [Kysely documentation](https://kysely.dev/docs/getting-started?dialect=pglite)
for more details.

## Knex.js

[Knex](https://knexjs.org/) is a stable, reliable Query Builder for various
Expand Down
Loading