kempo 4.5.6 → 4.5.7
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/package.json +1 -1
- package/server/db/index.js +14 -2
package/package.json
CHANGED
package/server/db/index.js
CHANGED
|
@@ -20,7 +20,15 @@ if(existsSync(appSchemaPath) && realpathSync(appSchemaPath) !== realpathSync(fra
|
|
|
20
20
|
|
|
21
21
|
const schema = { ...frameworkSchema, ...appSchema };
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/*
|
|
24
|
+
One database per process, whatever URL this module was loaded under. On Windows `c:\x` and `C:\x`
|
|
25
|
+
are different module URLs, so the same file can be evaluated twice (a test preload and a test file,
|
|
26
|
+
say), and the second evaluation would otherwise open a second connection, or boot a second in-memory
|
|
27
|
+
database that the first one's data is not in.
|
|
28
|
+
*/
|
|
29
|
+
const SINGLETON = Symbol.for('kempo.database');
|
|
30
|
+
|
|
31
|
+
let db = globalThis[SINGLETON];
|
|
24
32
|
|
|
25
33
|
/*
|
|
26
34
|
KEMPO_DB=pglite swaps the server for an in-process, in-memory Postgres (PGlite) with the schema
|
|
@@ -28,7 +36,9 @@ let db;
|
|
|
28
36
|
(jsonb, partial indexes, ON CONFLICT, triggers), not a mock. Nothing outside tests sets it, and
|
|
29
37
|
PGlite is a dev dependency that is only imported on this branch.
|
|
30
38
|
*/
|
|
31
|
-
if(
|
|
39
|
+
if(db){
|
|
40
|
+
// already created by an earlier evaluation of this module
|
|
41
|
+
} else if(process.env.KEMPO_DB === 'pglite'){
|
|
32
42
|
const [{ PGlite }, { drizzle: drizzlePglite }, { generateDrizzleJson, generateMigration }] = await Promise.all([
|
|
33
43
|
import('@electric-sql/pglite'),
|
|
34
44
|
import('drizzle-orm/pglite'),
|
|
@@ -71,4 +81,6 @@ if(process.env.KEMPO_DB === 'pglite'){
|
|
|
71
81
|
db = drizzle(postgres(process.env.DATABASE_URL), { schema });
|
|
72
82
|
}
|
|
73
83
|
|
|
84
|
+
globalThis[SINGLETON] = db;
|
|
85
|
+
|
|
74
86
|
export default db;
|