@sqb/postgres 4.15.0 → 4.16.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/esm/datatype-map.js +27 -30
- package/esm/index.js +5 -8
- package/esm/pg-adapter.js +8 -12
- package/esm/pg-connection.js +22 -26
- package/package.json +5 -5
package/esm/datatype-map.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return isArray ? postgrejs_1.DataTypeOIDs._text : postgrejs_1.DataTypeOIDs.text;
|
|
29
|
-
if (dataType === builder_1.DataType.JSON)
|
|
30
|
-
return isArray ? postgrejs_1.DataTypeOIDs._json : postgrejs_1.DataTypeOIDs.json;
|
|
1
|
+
import { DataType } from '@sqb/builder';
|
|
2
|
+
import { DataTypeOIDs } from 'postgrejs';
|
|
3
|
+
export function dataTypeToOID(dataType, isArray) {
|
|
4
|
+
if (dataType === DataType.DATE)
|
|
5
|
+
return isArray ? DataTypeOIDs._date : DataTypeOIDs.date;
|
|
6
|
+
if (dataType === DataType.BOOL)
|
|
7
|
+
return isArray ? DataTypeOIDs._bool : DataTypeOIDs.bool;
|
|
8
|
+
if (dataType === DataType.CHAR)
|
|
9
|
+
return isArray ? DataTypeOIDs._bpchar : DataTypeOIDs.bpchar;
|
|
10
|
+
if (dataType === DataType.SMALLINT)
|
|
11
|
+
return isArray ? DataTypeOIDs._int2 : DataTypeOIDs.int2;
|
|
12
|
+
if (dataType === DataType.INTEGER)
|
|
13
|
+
return isArray ? DataTypeOIDs._int4 : DataTypeOIDs.int4;
|
|
14
|
+
if (dataType === DataType.BIGINT)
|
|
15
|
+
return isArray ? DataTypeOIDs._int8 : DataTypeOIDs.int8;
|
|
16
|
+
if (dataType === DataType.BINARY)
|
|
17
|
+
return isArray ? DataTypeOIDs._bytea : DataTypeOIDs.bytea;
|
|
18
|
+
if (dataType === DataType.FLOAT)
|
|
19
|
+
return isArray ? DataTypeOIDs._float4 : DataTypeOIDs.float4;
|
|
20
|
+
if (dataType === DataType.DOUBLE)
|
|
21
|
+
return isArray ? DataTypeOIDs._float8 : DataTypeOIDs.float8;
|
|
22
|
+
if (dataType === DataType.GUID)
|
|
23
|
+
return isArray ? DataTypeOIDs._uuid : DataTypeOIDs.uuid;
|
|
24
|
+
if (dataType === DataType.TEXT)
|
|
25
|
+
return isArray ? DataTypeOIDs._text : DataTypeOIDs.text;
|
|
26
|
+
if (dataType === DataType.JSON)
|
|
27
|
+
return isArray ? DataTypeOIDs._json : DataTypeOIDs.json;
|
|
31
28
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const pg_adapter_js_1 = require("./pg-adapter.js");
|
|
7
|
-
connect_1.AdapterRegistry.register(new pg_adapter_js_1.PgAdapter());
|
|
8
|
-
tslib_1.__exportStar(require("./pg-adapter.js"), exports);
|
|
1
|
+
import '@sqb/postgres-dialect';
|
|
2
|
+
import { AdapterRegistry } from '@sqb/connect';
|
|
3
|
+
import { PgAdapter } from './pg-adapter.js';
|
|
4
|
+
AdapterRegistry.register(new PgAdapter());
|
|
5
|
+
export * from './pg-adapter.js';
|
package/esm/pg-adapter.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const postgrejs_1 = require("postgrejs");
|
|
7
|
-
const pg_connection_js_1 = require("./pg-connection.js");
|
|
8
|
-
class PgAdapter {
|
|
1
|
+
import '@sqb/postgres-dialect';
|
|
2
|
+
import { DataType } from '@sqb/connect';
|
|
3
|
+
import { Connection } from 'postgrejs';
|
|
4
|
+
import { PgConnection } from './pg-connection.js';
|
|
5
|
+
export class PgAdapter {
|
|
9
6
|
constructor() {
|
|
10
7
|
this.driver = 'postgrejs';
|
|
11
8
|
this.dialect = 'postgres';
|
|
12
9
|
this.features = {
|
|
13
10
|
cursor: true,
|
|
14
11
|
schema: true,
|
|
15
|
-
fetchAsString: [
|
|
12
|
+
fetchAsString: [DataType.DATE, DataType.TIMESTAMP, DataType.TIMESTAMPTZ],
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
async connect(config) {
|
|
@@ -29,10 +26,10 @@ class PgAdapter {
|
|
|
29
26
|
cfg.database = config.database;
|
|
30
27
|
if (config.schema)
|
|
31
28
|
cfg.schema = config.schema;
|
|
32
|
-
const connection = new
|
|
29
|
+
const connection = new Connection(cfg);
|
|
33
30
|
try {
|
|
34
31
|
await connection.connect();
|
|
35
|
-
return new
|
|
32
|
+
return new PgConnection(connection);
|
|
36
33
|
}
|
|
37
34
|
catch (e) {
|
|
38
35
|
await connection.close(0);
|
|
@@ -40,4 +37,3 @@ class PgAdapter {
|
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
exports.PgAdapter = PgAdapter;
|
package/esm/pg-connection.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const connect_1 = require("@sqb/connect");
|
|
5
|
-
const postgrejs_1 = require("postgrejs");
|
|
6
|
-
const datatype_map_js_1 = require("./datatype-map.js");
|
|
1
|
+
import { DataType } from '@sqb/connect';
|
|
2
|
+
import { BindParam, DataTypeOIDs } from 'postgrejs';
|
|
3
|
+
import { dataTypeToOID } from './datatype-map.js';
|
|
7
4
|
const SqbDataTypToOIDMap = {
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
5
|
+
[DataType.BOOL]: DataTypeOIDs.bool,
|
|
6
|
+
[DataType.CHAR]: DataTypeOIDs.char,
|
|
7
|
+
[DataType.VARCHAR]: DataTypeOIDs.varchar,
|
|
8
|
+
[DataType.SMALLINT]: DataTypeOIDs.int2,
|
|
9
|
+
[DataType.INTEGER]: DataTypeOIDs.int4,
|
|
10
|
+
[DataType.BIGINT]: DataTypeOIDs.int8,
|
|
11
|
+
[DataType.FLOAT]: DataTypeOIDs.float4,
|
|
12
|
+
[DataType.DOUBLE]: DataTypeOIDs.float8,
|
|
13
|
+
[DataType.NUMBER]: DataTypeOIDs.float8,
|
|
14
|
+
[DataType.DATE]: DataTypeOIDs.date,
|
|
15
|
+
[DataType.TIMESTAMP]: DataTypeOIDs.timestamp,
|
|
16
|
+
[DataType.TIMESTAMPTZ]: DataTypeOIDs.timestamptz,
|
|
17
|
+
[DataType.TIME]: DataTypeOIDs.time,
|
|
18
|
+
[DataType.BINARY]: DataTypeOIDs.bytea,
|
|
19
|
+
[DataType.TEXT]: DataTypeOIDs.text,
|
|
20
|
+
[DataType.GUID]: DataTypeOIDs.uuid,
|
|
24
21
|
};
|
|
25
|
-
class PgConnection {
|
|
22
|
+
export class PgConnection {
|
|
26
23
|
constructor(conn) {
|
|
27
24
|
this.intlcon = conn;
|
|
28
25
|
}
|
|
@@ -101,9 +98,9 @@ class PgConnection {
|
|
|
101
98
|
const params = query.params?.map((v, i) => {
|
|
102
99
|
const paramOpts = Array.isArray(query.paramOptions) ? query.paramOptions[i] : undefined;
|
|
103
100
|
if (v != null && paramOpts && paramOpts.dataType) {
|
|
104
|
-
const oid =
|
|
101
|
+
const oid = dataTypeToOID(paramOpts.dataType, paramOpts.isArray);
|
|
105
102
|
if (oid)
|
|
106
|
-
return new
|
|
103
|
+
return new BindParam(oid, v);
|
|
107
104
|
}
|
|
108
105
|
return v;
|
|
109
106
|
});
|
|
@@ -155,4 +152,3 @@ class PgConnection {
|
|
|
155
152
|
return result;
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
exports.PgConnection = PgConnection;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/postgres",
|
|
3
3
|
"description": "SQB serialization extension for PostgreSQL database",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.16.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"scripts": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"putil-promisify": "^1.10.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"postgrejs": "^2.
|
|
28
|
+
"postgrejs": "^2.17.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@sqb/builder": "^4.
|
|
32
|
-
"@sqb/connect": "^4.
|
|
33
|
-
"@sqb/postgres-dialect": "^4.
|
|
31
|
+
"@sqb/builder": "^4.16.0",
|
|
32
|
+
"@sqb/connect": "^4.16.0",
|
|
33
|
+
"@sqb/postgres-dialect": "^4.16.0",
|
|
34
34
|
"postgrejs": ">=2.15.1 <3.0.0"
|
|
35
35
|
},
|
|
36
36
|
"main": "./cjs/index.js",
|