knex-pglite
Version:
PGlite Dialect for Knex
79 lines (50 loc) • 1.73 kB
Markdown
# knex-pglite
[](https://www.npmjs.com/package/knex-pglite)
[](https://github.com/czeidler/knex-pglite/actions/workflows/ci.yml)
[PGlite](https://pglite.dev/) Dialect for [knex.js](http://knexjs.org)
Since PGlite is single user and only supports a single connection, this library doesn't allow users to configure
the connection pool in the `Knex.Config`.
Internally, the pool is set to `{ min: 1, max: 1 }`, i.e. there is exactly one connection at a time.
## Install
```bash
npm install knex-pglite
```
## Usage
```ts
import { knex } from "knex";
import ClientPgLite from "knex-pglite";
const instance = knex({
client: ClientPgLite,
dialect: "postgres",
// Use an empty object to use an in memory db
connection: {},
// OR use the filesystem:
// connection: { filename: 'path/to/my-pgdata' },
// OR use indexdb:
// connection: { connectionString: 'idb://my-pgdata' },
// OR provide own PGLite instance (experimental; no TypeScript types...)
// connection: () => ({ pglite: new PGLite() } as object)
});
```
## Changelog
### 0.14.0
No functional changes
- Reduce npm pack size by only including release files
- Switch to pnpm and update dev dependencies
- Add changelog
### 0.13.0
- Add option to pass PGlite instance through a connection function
### 0.12.1
- Add support for Knex `first` and `pluck`
### 0.10.0
- Add support ESM
### 0.9.8
- Update to PGlite 0.2.14
### 0.9.4
- Enforce single DB connection
### 0.9.1
- Initial version
## Acknowledgements
Mostly based on the build-in knex Postgres/Sqlite dialects.
## License
[MIT License](LICENSE)