@storecraft/database-postgres 1.0.9 → 1.0.11
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/index.js +37 -2
- package/package.json +1 -1
- package/types.public.d.ts +1 -1
package/index.js
CHANGED
@@ -1,16 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js';
|
3
|
+
* @import { ENV } from '@storecraft/core';
|
4
|
+
*
|
5
|
+
*/
|
1
6
|
import { SQL } from '@storecraft/database-sql-base';
|
2
7
|
import { PostgresDialect } from 'kysely';
|
3
8
|
import pg from 'pg';
|
4
9
|
|
10
|
+
|
5
11
|
/**
|
6
12
|
* @description `postgres` driver for storecraft using the `pg` driver
|
7
13
|
*
|
8
14
|
*/
|
9
15
|
export class Postgres extends SQL {
|
10
16
|
|
17
|
+
/** @satisfies {ENV<Config>} */
|
18
|
+
static EnvConfig = /** @type{const} */ ({
|
19
|
+
pool_config: {
|
20
|
+
host: 'POSTGRES_HOST',
|
21
|
+
port: 'POSTGRES_PORT',
|
22
|
+
user: 'POSTGRES_USER',
|
23
|
+
password: 'POSTGRES_PASSWORD',
|
24
|
+
}
|
25
|
+
});
|
26
|
+
|
11
27
|
/**
|
12
28
|
*
|
13
|
-
* @param {
|
29
|
+
* @param {Config} [config] config
|
14
30
|
*/
|
15
31
|
constructor(config) {
|
16
32
|
super(
|
@@ -18,13 +34,32 @@ export class Postgres extends SQL {
|
|
18
34
|
dialect_type: 'POSTGRES',
|
19
35
|
dialect: new PostgresDialect(
|
20
36
|
{
|
21
|
-
pool: new pg.Pool(config.pool_config),
|
37
|
+
pool: async () => new pg.Pool(config.pool_config),
|
22
38
|
cursor: config.cursor
|
23
39
|
}
|
24
40
|
),
|
25
41
|
}
|
26
42
|
);
|
27
43
|
|
44
|
+
// abit hacky :0
|
45
|
+
this.pg_config = config;
|
28
46
|
}
|
29
47
|
|
48
|
+
/** @type {SQL["init"]} */
|
49
|
+
init = (app) => {
|
50
|
+
this.pg_config.pool_config.host ??=
|
51
|
+
app.platform.env[Postgres.EnvConfig.pool_config.host];
|
52
|
+
|
53
|
+
this.pg_config.pool_config.port ??=
|
54
|
+
parseFloat(app.platform.env[Postgres.EnvConfig.pool_config.port]);
|
55
|
+
|
56
|
+
this.pg_config.pool_config.user ??=
|
57
|
+
app.platform.env[Postgres.EnvConfig.pool_config.user];
|
58
|
+
|
59
|
+
this.pg_config.pool_config.password ??=
|
60
|
+
app.platform.env[Postgres.EnvConfig.pool_config.password];
|
61
|
+
|
62
|
+
super.init(app);
|
63
|
+
}
|
64
|
+
|
30
65
|
}
|
package/package.json
CHANGED
package/types.public.d.ts
CHANGED