duron 0.1.1 → 0.2.0
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/README.md +4 -4
- package/dist/adapters/postgres/base.d.ts +52 -0
- package/dist/adapters/postgres/base.d.ts.map +1 -0
- package/dist/adapters/postgres/base.js +832 -0
- package/dist/adapters/postgres/pglite.d.ts +10 -5
- package/dist/adapters/postgres/pglite.d.ts.map +1 -1
- package/dist/adapters/postgres/pglite.js +19 -7
- package/dist/adapters/postgres/postgres.d.ts +6 -39
- package/dist/adapters/postgres/postgres.d.ts.map +1 -1
- package/dist/adapters/postgres/postgres.js +9 -822
- package/dist/adapters/postgres/schema.d.ts +89 -135
- package/dist/adapters/postgres/schema.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.d.ts +89 -135
- package/dist/adapters/postgres/schema.default.d.ts.map +1 -1
- package/migrations/postgres/20251203223656_conscious_johnny_blaze/migration.sql +64 -0
- package/migrations/postgres/20251203223656_conscious_johnny_blaze/snapshot.json +954 -0
- package/package.json +3 -3
- package/src/adapters/postgres/base.ts +1297 -0
- package/src/adapters/postgres/pglite.ts +36 -18
- package/src/adapters/postgres/postgres.ts +19 -1244
- package/migrations/postgres/0000_lethal_speed_demon.sql +0 -64
- package/migrations/postgres/meta/0000_snapshot.json +0 -606
- package/migrations/postgres/meta/_journal.json +0 -13
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
|
|
1
3
|
import { drizzle } from 'drizzle-orm/pglite'
|
|
4
|
+
import { migrate } from 'drizzle-orm/pglite/migrator'
|
|
5
|
+
|
|
6
|
+
import { type AdapterOptions, PostgresBaseAdapter } from './base.js'
|
|
7
|
+
import type createSchema from './schema.js'
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
import { type DB, PostgresAdapter } from './postgres.js'
|
|
9
|
+
type Schema = ReturnType<typeof createSchema>
|
|
5
10
|
|
|
6
|
-
type
|
|
11
|
+
export type DB = ReturnType<typeof drizzle<Schema>>
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* PGLite adapter implementation for Duron.
|
|
@@ -11,9 +16,27 @@ type PGLiteDB = ReturnType<typeof drizzle>
|
|
|
11
16
|
*
|
|
12
17
|
* @template Options - The adapter options type
|
|
13
18
|
*/
|
|
14
|
-
export class PGLiteAdapter extends
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
export class PGLiteAdapter extends PostgresBaseAdapter<DB, string | undefined> {
|
|
20
|
+
/**
|
|
21
|
+
* Start the adapter.
|
|
22
|
+
* Runs migrations if enabled and sets up database listeners.
|
|
23
|
+
*
|
|
24
|
+
* @returns Promise resolving to `true` if started successfully, `false` otherwise
|
|
25
|
+
*/
|
|
26
|
+
protected override async _start() {
|
|
27
|
+
if (this.migrateOnStart) {
|
|
28
|
+
await migrate(this.db, {
|
|
29
|
+
migrationsFolder: join(import.meta.dirname, '..', '..', '..', 'migrations', 'postgres'),
|
|
30
|
+
migrationsTable: 'migrations',
|
|
31
|
+
migrationsSchema: 'duron',
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await super._start()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected override async _stop() {
|
|
39
|
+
await this.db?.$client.close()
|
|
17
40
|
}
|
|
18
41
|
|
|
19
42
|
/**
|
|
@@ -34,8 +57,8 @@ export class PGLiteAdapter extends PostgresAdapter {
|
|
|
34
57
|
protected override _initDb() {
|
|
35
58
|
let connection = ':memory:'
|
|
36
59
|
// it means that the user is using a file path, so we need to use the file path
|
|
37
|
-
if (typeof this.
|
|
38
|
-
connection = this.
|
|
60
|
+
if (typeof this.connection === 'string' && !this.connection.startsWith('postgres://')) {
|
|
61
|
+
connection = this.connection
|
|
39
62
|
}
|
|
40
63
|
if (connection === ':memory:') {
|
|
41
64
|
this.db = drizzle() as unknown as DB
|
|
@@ -52,9 +75,7 @@ export class PGLiteAdapter extends PostgresAdapter {
|
|
|
52
75
|
* @returns Promise resolving to `void`
|
|
53
76
|
*/
|
|
54
77
|
protected override async _notify(event: string, data: any): Promise<void> {
|
|
55
|
-
await
|
|
56
|
-
`NOTIFY "${this.options.schema}.${event}", '${JSON.stringify(data)}'`,
|
|
57
|
-
)
|
|
78
|
+
await this.db?.$client.query(`NOTIFY "${this.schema}.${event}", '${JSON.stringify(data)}'`)
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
/**
|
|
@@ -68,12 +89,9 @@ export class PGLiteAdapter extends PostgresAdapter {
|
|
|
68
89
|
event: string,
|
|
69
90
|
callback: (payload: string) => void,
|
|
70
91
|
): Promise<{ unlisten: () => void }> {
|
|
71
|
-
const unlisten = await (this.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
callback(payload)
|
|
75
|
-
},
|
|
76
|
-
)
|
|
92
|
+
const unlisten = await this.db?.$client.listen(`"${this.schema}.${event}"`, (payload: string) => {
|
|
93
|
+
callback(payload)
|
|
94
|
+
})
|
|
77
95
|
|
|
78
96
|
return {
|
|
79
97
|
unlisten,
|
|
@@ -81,6 +99,6 @@ export class PGLiteAdapter extends PostgresAdapter {
|
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
|
|
84
|
-
export const pgliteAdapter = (options:
|
|
102
|
+
export const pgliteAdapter = (options: AdapterOptions<string | undefined>) => {
|
|
85
103
|
return new PGLiteAdapter(options)
|
|
86
104
|
}
|