@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.
@@ -1,31 +1,28 @@
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;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- require("@sqb/postgres-dialect");
5
- const connect_1 = require("@sqb/connect");
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PgAdapter = void 0;
4
- require("@sqb/postgres-dialect");
5
- const connect_1 = require("@sqb/connect");
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: [connect_1.DataType.DATE, connect_1.DataType.TIMESTAMP, connect_1.DataType.TIMESTAMPTZ],
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 postgrejs_1.Connection(cfg);
29
+ const connection = new Connection(cfg);
33
30
  try {
34
31
  await connection.connect();
35
- return new pg_connection_js_1.PgConnection(connection);
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;
@@ -1,28 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PgConnection = void 0;
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
- [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,
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 = (0, datatype_map_js_1.dataTypeToOID)(paramOpts.dataType, paramOpts.isArray);
101
+ const oid = dataTypeToOID(paramOpts.dataType, paramOpts.isArray);
105
102
  if (oid)
106
- return new postgrejs_1.BindParam(oid, v);
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.15.0",
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.16.0"
28
+ "postgrejs": "^2.17.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@sqb/builder": "^4.15.0",
32
- "@sqb/connect": "^4.15.0",
33
- "@sqb/postgres-dialect": "^4.15.0",
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",