@kubun/db-postgres 0.10.0 → 0.11.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/lib/index.js +39 -1
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
import{AbstractPostgresAdapter
|
|
1
|
+
import { AbstractPostgresAdapter } from '@kubun/db-adapter';
|
|
2
|
+
import { PostgresJSDialect } from 'kysely-postgres-js';
|
|
3
|
+
import postgres from 'postgres';
|
|
4
|
+
export class PostgresAdapter extends AbstractPostgresAdapter {
|
|
5
|
+
#dialect;
|
|
6
|
+
constructor(params){
|
|
7
|
+
super();
|
|
8
|
+
// postgres.js returns int8/bigint columns as strings by default to avoid
|
|
9
|
+
// precision loss. Our bigint columns hold ms-epoch values (well under
|
|
10
|
+
// 2^53), and the table types declare them as `number`, so parse them back
|
|
11
|
+
// to numbers on read. Caller-supplied `types` still take precedence.
|
|
12
|
+
//
|
|
13
|
+
// NOTE: this parser is connection-global — it applies to EVERY int8 read
|
|
14
|
+
// (including `COUNT()` results), not just the hub ms-epoch columns. Safe
|
|
15
|
+
// today because all int8 values in use are < 2^53 (Number.MAX_SAFE_INTEGER).
|
|
16
|
+
// A future column holding genuinely large bigints (e.g. a snowflake ID)
|
|
17
|
+
// would lose precision here and must opt out via a `BigInt`-returning type.
|
|
18
|
+
const options = {
|
|
19
|
+
...params.options,
|
|
20
|
+
types: {
|
|
21
|
+
int8: {
|
|
22
|
+
to: 20,
|
|
23
|
+
from: [
|
|
24
|
+
20
|
|
25
|
+
],
|
|
26
|
+
serialize: (value)=>String(value),
|
|
27
|
+
parse: (value)=>Number(value)
|
|
28
|
+
},
|
|
29
|
+
...params.options?.types
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
this.#dialect = new PostgresJSDialect({
|
|
33
|
+
postgres: postgres(params.url, options)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
get dialect() {
|
|
37
|
+
return this.#dialect;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/db-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"kysely": "^0.29.2",
|
|
19
19
|
"kysely-postgres-js": "^3.0.0",
|
|
20
20
|
"postgres": "^3.4.8",
|
|
21
|
-
"@kubun/db-adapter": "^0.
|
|
21
|
+
"@kubun/db-adapter": "^0.11.0"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build:clean": "del lib",
|
|
25
|
-
"build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
|
|
25
|
+
"build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
26
26
|
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
27
27
|
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
28
28
|
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|