UNPKG

@jadejr/kysely-pglite

Version:

Kysely dialect for @electric-sql/pglite (temporary fork https://github.com/dnlsandiego/kysely-pglite)

73 lines 1.9 kB
import { isString } from '@sindresorhus/is'; import fs from 'fs-extra'; import { PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, } from 'kysely'; import { PGliteDriver } from './pglite-driver.js'; /** * * PGlite dialect that uses the [@electric-sql/pglite](https://pglite.dev) library. * * The constructor takes an instance of {@link PGliteDialectConfig}. * * ```ts * import { PGlite } from '@electric-sql/pglite' * import { PGliteDialect } from 'kysely-pglite' * * new PGliteDialect({ * PGlite: new PGlite({ * 'dataDir': '/path/to/dataDir', * // other options * }) * }) * ``` * * If you want PGlite to only be created once it's first used, `PGlite` * can be a function: * * The constructor takes an instance of {@link PGliteDialectConfig}. * * ```ts * import { PGlite } from '@electric-sql/pglite' * import { PGliteDialect } from 'kysely-pglite' * * new PGliteDialect({ * PGlite: async () => new PGlite({ * 'dataDir: '/path/to/dataDir', * // other options * }) * }) * ``` * * You can also let the dialect create the PGlite instance for you while using PGlite's options * * ```ts * new PGliteDialect({ * PGliteOptions: { * 'dataDir: '/path/to/dataDir', * // other options * } * }) * ``` */ export class PGliteDialect { #config; constructor(config) { this.#config = config; const options = config.PGliteOptions; if (options?.dataDir && isString(options.dataDir)) { fs.ensureDirSync(options.dataDir); } } createDriver() { return new PGliteDriver(this.#config); } createQueryCompiler() { return new PostgresQueryCompiler(); } createAdapter() { return new PostgresAdapter(); } createIntrospector(db) { return new PostgresIntrospector(db); } } //# sourceMappingURL=pglite-dialect.js.map