@arki/db 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/ids.d.ts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/dot.d.ts +28 -12
- package/dist/dot.d.ts.map +1 -1
- package/dist/dot.js +49 -18
- package/dist/dot.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +14 -10
- package/dist/env.js.map +1 -1
- package/package.json +12 -5
- package/src/builder.ts +359 -0
- package/src/bun.ts +58 -0
- package/src/client/README.md +5 -0
- package/src/client/ids.ts +11 -0
- package/src/client/index.ts +11 -0
- package/src/connection-options.ts +49 -0
- package/src/debug.ts +24 -0
- package/src/dot.ts +200 -0
- package/src/env.ts +92 -0
- package/src/factory.ts +47 -0
- package/src/id-factory.ts +172 -0
- package/src/id.ts +12 -0
- package/src/init.bun.ts +58 -0
- package/src/init.ts +48 -0
- package/src/orm.ts +9 -0
- package/src/pg.ts +1 -0
- package/src/runtime-local.ts +48 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AnyRelations } from 'drizzle-orm';
|
|
2
|
+
import { PGlite, type Extension } from '@electric-sql/pglite';
|
|
3
|
+
import { drizzle, type PgliteDatabase } from 'drizzle-orm/pglite';
|
|
4
|
+
|
|
5
|
+
import { debugInit } from './debug.js';
|
|
6
|
+
|
|
7
|
+
export type PgliteInitOptions = {
|
|
8
|
+
/** Path to the PGlite data directory. Defaults to `./.local/db`. */
|
|
9
|
+
dataDir?: string;
|
|
10
|
+
/** Use an in-memory database (overrides dataDir). */
|
|
11
|
+
memory?: boolean;
|
|
12
|
+
/** PGlite extensions to load (e.g. `{ vector }` from `@electric-sql/pglite/vector`). */
|
|
13
|
+
extensions?: Record<string, Extension>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initialize a PGlite-backed Drizzle database for embedded local development.
|
|
18
|
+
*
|
|
19
|
+
* Returns the raw PGlite instance alongside the Drizzle handle so callers can
|
|
20
|
+
* share it with `@arki/queue/runtime-local` (one process, one PGlite).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { initDbRuntimeLocal } from '@arki/db/runtime-local';
|
|
25
|
+
* const { db, pglite } = await initDbRuntimeLocal({ dataDir: './.local/db' }, { relations });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export async function initDbRuntimeLocal<TRelations extends AnyRelations>(
|
|
29
|
+
options: PgliteInitOptions,
|
|
30
|
+
config: { relations: TRelations },
|
|
31
|
+
): Promise<{ db: PgliteDatabase<TRelations>; pglite: PGlite }> {
|
|
32
|
+
const url = options.memory === true ? 'memory://' : (options.dataDir ?? './.local/db');
|
|
33
|
+
debugInit('[runtime-local] Initializing PGlite at: %s', url);
|
|
34
|
+
|
|
35
|
+
const pglite = options.extensions
|
|
36
|
+
? new PGlite(url, { extensions: options.extensions })
|
|
37
|
+
: new PGlite(url);
|
|
38
|
+
await pglite.waitReady;
|
|
39
|
+
debugInit('[runtime-local] PGlite ready');
|
|
40
|
+
|
|
41
|
+
const db = drizzle({
|
|
42
|
+
client: pglite,
|
|
43
|
+
relations: config.relations,
|
|
44
|
+
}) as PgliteDatabase<TRelations>;
|
|
45
|
+
|
|
46
|
+
debugInit('[runtime-local] Drizzle database initialized');
|
|
47
|
+
return { db, pglite };
|
|
48
|
+
}
|