@sqb/postgres 4.17.0 → 4.19.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/cjs/pg-connection.js +18 -19
- package/esm/pg-connection.js +18 -19
- package/package.json +5 -5
- package/cjs/datatype-map.js +0 -31
- package/esm/datatype-map.js +0 -28
- package/types/datatype-map.d.ts +0 -3
package/cjs/pg-connection.js
CHANGED
|
@@ -3,24 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PgConnection = void 0;
|
|
4
4
|
const connect_1 = require("@sqb/connect");
|
|
5
5
|
const postgrejs_1 = require("postgrejs");
|
|
6
|
-
const datatype_map_js_1 = require("./datatype-map.js");
|
|
7
6
|
const SqbDataTypToOIDMap = {
|
|
8
|
-
[connect_1.DataType.BOOL]: postgrejs_1.DataTypeOIDs.bool,
|
|
9
|
-
[connect_1.DataType.CHAR]: postgrejs_1.DataTypeOIDs.char,
|
|
10
|
-
[connect_1.DataType.VARCHAR]: postgrejs_1.DataTypeOIDs.varchar,
|
|
11
|
-
[connect_1.DataType.SMALLINT]: postgrejs_1.DataTypeOIDs.int2,
|
|
12
|
-
[connect_1.DataType.INTEGER]: postgrejs_1.DataTypeOIDs.int4,
|
|
13
|
-
[connect_1.DataType.BIGINT]: postgrejs_1.DataTypeOIDs.int8,
|
|
14
|
-
[connect_1.DataType.FLOAT]: postgrejs_1.DataTypeOIDs.float4,
|
|
15
|
-
[connect_1.DataType.DOUBLE]: postgrejs_1.DataTypeOIDs.float8,
|
|
16
|
-
[connect_1.DataType.NUMBER]: postgrejs_1.DataTypeOIDs.float8,
|
|
17
|
-
[connect_1.DataType.DATE]: postgrejs_1.DataTypeOIDs.date,
|
|
18
|
-
[connect_1.DataType.TIMESTAMP]: postgrejs_1.DataTypeOIDs.timestamp,
|
|
19
|
-
[connect_1.DataType.TIMESTAMPTZ]: postgrejs_1.DataTypeOIDs.timestamptz,
|
|
20
|
-
[connect_1.DataType.TIME]: postgrejs_1.DataTypeOIDs.time,
|
|
21
|
-
[connect_1.DataType.BINARY]: postgrejs_1.DataTypeOIDs.bytea,
|
|
22
|
-
[connect_1.DataType.TEXT]: postgrejs_1.DataTypeOIDs.text,
|
|
23
|
-
[connect_1.DataType.GUID]: postgrejs_1.DataTypeOIDs.uuid,
|
|
7
|
+
[connect_1.DataType.BOOL]: [postgrejs_1.DataTypeOIDs.bool, postgrejs_1.DataTypeOIDs._bool],
|
|
8
|
+
[connect_1.DataType.CHAR]: [postgrejs_1.DataTypeOIDs.char, postgrejs_1.DataTypeOIDs._char],
|
|
9
|
+
[connect_1.DataType.VARCHAR]: [postgrejs_1.DataTypeOIDs.varchar, postgrejs_1.DataTypeOIDs._varchar],
|
|
10
|
+
[connect_1.DataType.SMALLINT]: [postgrejs_1.DataTypeOIDs.int2, postgrejs_1.DataTypeOIDs._int2],
|
|
11
|
+
[connect_1.DataType.INTEGER]: [postgrejs_1.DataTypeOIDs.int4, postgrejs_1.DataTypeOIDs._int4],
|
|
12
|
+
[connect_1.DataType.BIGINT]: [postgrejs_1.DataTypeOIDs.int8, postgrejs_1.DataTypeOIDs._int8],
|
|
13
|
+
[connect_1.DataType.FLOAT]: [postgrejs_1.DataTypeOIDs.float4, postgrejs_1.DataTypeOIDs._float4],
|
|
14
|
+
[connect_1.DataType.DOUBLE]: [postgrejs_1.DataTypeOIDs.float8, postgrejs_1.DataTypeOIDs._float8],
|
|
15
|
+
[connect_1.DataType.NUMBER]: [postgrejs_1.DataTypeOIDs.float8, postgrejs_1.DataTypeOIDs._float8],
|
|
16
|
+
[connect_1.DataType.DATE]: [postgrejs_1.DataTypeOIDs.date, postgrejs_1.DataTypeOIDs._date],
|
|
17
|
+
[connect_1.DataType.TIMESTAMP]: [postgrejs_1.DataTypeOIDs.timestamp, postgrejs_1.DataTypeOIDs._timestamp],
|
|
18
|
+
[connect_1.DataType.TIMESTAMPTZ]: [postgrejs_1.DataTypeOIDs.timestamptz, postgrejs_1.DataTypeOIDs._timestamptz],
|
|
19
|
+
[connect_1.DataType.TIME]: [postgrejs_1.DataTypeOIDs.time, postgrejs_1.DataTypeOIDs._time],
|
|
20
|
+
[connect_1.DataType.BINARY]: [postgrejs_1.DataTypeOIDs.bytea, postgrejs_1.DataTypeOIDs._bytea],
|
|
21
|
+
[connect_1.DataType.TEXT]: [postgrejs_1.DataTypeOIDs.text, postgrejs_1.DataTypeOIDs._text],
|
|
22
|
+
[connect_1.DataType.GUID]: [postgrejs_1.DataTypeOIDs.uuid, postgrejs_1.DataTypeOIDs._uuid],
|
|
24
23
|
};
|
|
25
24
|
class PgConnection {
|
|
26
25
|
constructor(conn) {
|
|
@@ -101,7 +100,7 @@ class PgConnection {
|
|
|
101
100
|
const params = query.params?.map((v, i) => {
|
|
102
101
|
const paramOpts = Array.isArray(query.paramOptions) ? query.paramOptions[i] : undefined;
|
|
103
102
|
if (v != null && paramOpts && paramOpts.dataType) {
|
|
104
|
-
const oid =
|
|
103
|
+
const oid = SqbDataTypToOIDMap[paramOpts.dataType]?.[paramOpts.isArray ? 1 : 0];
|
|
105
104
|
if (oid)
|
|
106
105
|
return new postgrejs_1.BindParam(oid, v);
|
|
107
106
|
}
|
|
@@ -116,7 +115,7 @@ class PgConnection {
|
|
|
116
115
|
};
|
|
117
116
|
if (query.fetchAsString) {
|
|
118
117
|
const items = query.fetchAsString.reduce((a, v) => {
|
|
119
|
-
const oid = SqbDataTypToOIDMap[v];
|
|
118
|
+
const oid = SqbDataTypToOIDMap[v][0];
|
|
120
119
|
if (oid)
|
|
121
120
|
a.push(oid);
|
|
122
121
|
return a;
|
package/esm/pg-connection.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { DataType } from '@sqb/connect';
|
|
2
2
|
import { BindParam, DataTypeOIDs } from 'postgrejs';
|
|
3
|
-
import { dataTypeToOID } from './datatype-map.js';
|
|
4
3
|
const SqbDataTypToOIDMap = {
|
|
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,
|
|
4
|
+
[DataType.BOOL]: [DataTypeOIDs.bool, DataTypeOIDs._bool],
|
|
5
|
+
[DataType.CHAR]: [DataTypeOIDs.char, DataTypeOIDs._char],
|
|
6
|
+
[DataType.VARCHAR]: [DataTypeOIDs.varchar, DataTypeOIDs._varchar],
|
|
7
|
+
[DataType.SMALLINT]: [DataTypeOIDs.int2, DataTypeOIDs._int2],
|
|
8
|
+
[DataType.INTEGER]: [DataTypeOIDs.int4, DataTypeOIDs._int4],
|
|
9
|
+
[DataType.BIGINT]: [DataTypeOIDs.int8, DataTypeOIDs._int8],
|
|
10
|
+
[DataType.FLOAT]: [DataTypeOIDs.float4, DataTypeOIDs._float4],
|
|
11
|
+
[DataType.DOUBLE]: [DataTypeOIDs.float8, DataTypeOIDs._float8],
|
|
12
|
+
[DataType.NUMBER]: [DataTypeOIDs.float8, DataTypeOIDs._float8],
|
|
13
|
+
[DataType.DATE]: [DataTypeOIDs.date, DataTypeOIDs._date],
|
|
14
|
+
[DataType.TIMESTAMP]: [DataTypeOIDs.timestamp, DataTypeOIDs._timestamp],
|
|
15
|
+
[DataType.TIMESTAMPTZ]: [DataTypeOIDs.timestamptz, DataTypeOIDs._timestamptz],
|
|
16
|
+
[DataType.TIME]: [DataTypeOIDs.time, DataTypeOIDs._time],
|
|
17
|
+
[DataType.BINARY]: [DataTypeOIDs.bytea, DataTypeOIDs._bytea],
|
|
18
|
+
[DataType.TEXT]: [DataTypeOIDs.text, DataTypeOIDs._text],
|
|
19
|
+
[DataType.GUID]: [DataTypeOIDs.uuid, DataTypeOIDs._uuid],
|
|
21
20
|
};
|
|
22
21
|
export class PgConnection {
|
|
23
22
|
constructor(conn) {
|
|
@@ -98,7 +97,7 @@ export class PgConnection {
|
|
|
98
97
|
const params = query.params?.map((v, i) => {
|
|
99
98
|
const paramOpts = Array.isArray(query.paramOptions) ? query.paramOptions[i] : undefined;
|
|
100
99
|
if (v != null && paramOpts && paramOpts.dataType) {
|
|
101
|
-
const oid =
|
|
100
|
+
const oid = SqbDataTypToOIDMap[paramOpts.dataType]?.[paramOpts.isArray ? 1 : 0];
|
|
102
101
|
if (oid)
|
|
103
102
|
return new BindParam(oid, v);
|
|
104
103
|
}
|
|
@@ -113,7 +112,7 @@ export class PgConnection {
|
|
|
113
112
|
};
|
|
114
113
|
if (query.fetchAsString) {
|
|
115
114
|
const items = query.fetchAsString.reduce((a, v) => {
|
|
116
|
-
const oid = SqbDataTypToOIDMap[v];
|
|
115
|
+
const oid = SqbDataTypToOIDMap[v][0];
|
|
117
116
|
if (oid)
|
|
118
117
|
a.push(oid);
|
|
119
118
|
return a;
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/postgres",
|
|
3
3
|
"description": "SQB serialization extension for PostgreSQL database",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.19.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"putil-promisify": "^1.10.1",
|
|
9
|
-
"tslib": "^2.
|
|
9
|
+
"tslib": "^2.7.0"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@sqb/builder": "^4.
|
|
13
|
-
"@sqb/connect": "^4.
|
|
14
|
-
"@sqb/postgres-dialect": "^4.
|
|
12
|
+
"@sqb/builder": "^4.19.0",
|
|
13
|
+
"@sqb/connect": "^4.19.0",
|
|
14
|
+
"@sqb/postgres-dialect": "^4.19.0",
|
|
15
15
|
"postgrejs": ">=2.15.1 <3.0.0"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
package/cjs/datatype-map.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dataTypeToOID = dataTypeToOID;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const postgrejs_1 = require("postgrejs");
|
|
6
|
-
function dataTypeToOID(dataType, isArray) {
|
|
7
|
-
if (dataType === builder_1.DataType.DATE)
|
|
8
|
-
return isArray ? postgrejs_1.DataTypeOIDs._date : postgrejs_1.DataTypeOIDs.date;
|
|
9
|
-
if (dataType === builder_1.DataType.BOOL)
|
|
10
|
-
return isArray ? postgrejs_1.DataTypeOIDs._bool : postgrejs_1.DataTypeOIDs.bool;
|
|
11
|
-
if (dataType === builder_1.DataType.CHAR)
|
|
12
|
-
return isArray ? postgrejs_1.DataTypeOIDs._bpchar : postgrejs_1.DataTypeOIDs.bpchar;
|
|
13
|
-
if (dataType === builder_1.DataType.SMALLINT)
|
|
14
|
-
return isArray ? postgrejs_1.DataTypeOIDs._int2 : postgrejs_1.DataTypeOIDs.int2;
|
|
15
|
-
if (dataType === builder_1.DataType.INTEGER)
|
|
16
|
-
return isArray ? postgrejs_1.DataTypeOIDs._int4 : postgrejs_1.DataTypeOIDs.int4;
|
|
17
|
-
if (dataType === builder_1.DataType.BIGINT)
|
|
18
|
-
return isArray ? postgrejs_1.DataTypeOIDs._int8 : postgrejs_1.DataTypeOIDs.int8;
|
|
19
|
-
if (dataType === builder_1.DataType.BINARY)
|
|
20
|
-
return isArray ? postgrejs_1.DataTypeOIDs._bytea : postgrejs_1.DataTypeOIDs.bytea;
|
|
21
|
-
if (dataType === builder_1.DataType.FLOAT)
|
|
22
|
-
return isArray ? postgrejs_1.DataTypeOIDs._float4 : postgrejs_1.DataTypeOIDs.float4;
|
|
23
|
-
if (dataType === builder_1.DataType.DOUBLE)
|
|
24
|
-
return isArray ? postgrejs_1.DataTypeOIDs._float8 : postgrejs_1.DataTypeOIDs.float8;
|
|
25
|
-
if (dataType === builder_1.DataType.GUID)
|
|
26
|
-
return isArray ? postgrejs_1.DataTypeOIDs._uuid : postgrejs_1.DataTypeOIDs.uuid;
|
|
27
|
-
if (dataType === builder_1.DataType.TEXT)
|
|
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;
|
|
31
|
-
}
|
package/esm/datatype-map.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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;
|
|
28
|
-
}
|
package/types/datatype-map.d.ts
DELETED