Skip to content

Commit

Permalink
Add TypeORM support for PGlite (#407)
Browse files Browse the repository at this point in the history
* Add TypeORM support

* Tweak wording

---------

Co-authored-by: Sam Willis <[email protected]>
  • Loading branch information
muraliprajapati and samwillis authored Nov 12, 2024
1 parent c442c88 commit e1f532f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/docs/orm-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,38 @@ export const db = knex({
Now you can check [Knex documentation](https://knexjs.org/guide/query-builder.html)
and [knex-pglite](https://github.com/czeidler/knex-pglite) documentation for
more details.

## TypeORM

[TypeORM](https://typeorm.io/) is an ORM that can run in NodeJS, the Browser, and many other platforms. Key features include:

- Clean object-relational model
- Eager and lazy associations (relations)
- Automatic migration generation
- Elegant-syntax, flexible and powerful QueryBuilder.

To use TypeORM with PGlite, add the third party [typeorm-pglite](https://www.npmjs.com/package/typeorm-pglite)
library to your project:

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

typeorm-pglite works with TypeORM's existing postgres dialect. Just provide the PGliteDriver to the driver data source option:

```javascript
import { PGliteDriver, getPGliteInstance } from 'typeorm-pglite'
import { DataSource } from 'typeorm'

const PGliteDataSource = new DataSource({
type: 'postgres',
driver: new PGliteDriver().driver,
})

// You can access the internal PGlite instance using getPGliteInstance function
const pgliteDb = await getPGliteInstance()
```

Check [TypeORM documentation](https://typeorm.io/data-source)
and [typeorm-pglite](https://github.com/muraliprajapati/typeorm-pglite) documentation for
more details.

0 comments on commit e1f532f

Please sign in to comment.