@sqb/postgres 4.20.6 → 4.21.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/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.20.6",
4
+ "version": "4.21.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
@@ -9,29 +9,24 @@
9
9
  "tslib": "^2.8.1"
10
10
  },
11
11
  "peerDependencies": {
12
- "@sqb/builder": "^4.20.6",
13
- "@sqb/connect": "^4.20.6",
14
- "@sqb/postgres-dialect": "^4.20.6",
12
+ "@sqb/builder": "^4.21.0",
13
+ "@sqb/connect": "^4.21.0",
14
+ "@sqb/postgres-dialect": "^4.21.0",
15
15
  "postgrejs": ">=2.15.1 <3.0.0"
16
16
  },
17
17
  "type": "module",
18
+ "module": "./index.js",
19
+ "types": "./index.d.ts",
18
20
  "exports": {
19
21
  ".": {
20
- "import": {
21
- "types": "./types/index.d.ts",
22
- "default": "./esm/index.js"
23
- },
24
- "require": {
25
- "types": "./types/index.d.cts",
26
- "default": "./cjs/index.js"
27
- },
28
- "default": "./esm/index.js"
22
+ "types": "./index.d.ts",
23
+ "default": "./index.js"
29
24
  },
30
25
  "./package.json": "./package.json"
31
26
  },
32
- "main": "./cjs/index.js",
33
- "module": "./esm/index.js",
34
- "types": "./types/index.d.ts",
27
+ "engines": {
28
+ "node": ">=20.0"
29
+ },
35
30
  "contributors": [
36
31
  "Eray Hanoglu <e.hanoglu@panates.com>",
37
32
  "Ilker Gurelli <i.gurelli@panates.com>"
@@ -41,17 +36,6 @@
41
36
  "url": "https://github.com/panates/sqb.git",
42
37
  "directory": "packages/postgres"
43
38
  },
44
- "engines": {
45
- "node": ">=18.0"
46
- },
47
- "files": [
48
- "bin/",
49
- "cjs/",
50
- "esm/",
51
- "types/",
52
- "LICENSE",
53
- "README.md"
54
- ],
55
39
  "keywords": [
56
40
  "sqb",
57
41
  "postgressql",
package/cjs/index.js DELETED
@@ -1,8 +0,0 @@
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);
package/cjs/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
package/cjs/pg-adapter.js DELETED
@@ -1,41 +0,0 @@
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 {
9
- driver = 'postgrejs';
10
- dialect = 'postgres';
11
- features = {
12
- cursor: true,
13
- schema: true,
14
- fetchAsString: [connect_1.DataType.DATE, connect_1.DataType.TIMESTAMP, connect_1.DataType.TIMESTAMPTZ],
15
- };
16
- async connect(config) {
17
- const cfg = { ...config.driverOptions };
18
- if (config.user)
19
- cfg.user = config.user;
20
- if (config.password)
21
- cfg.password = config.password;
22
- if (config.host)
23
- cfg.host = config.host;
24
- if (config.port)
25
- cfg.port = config.port;
26
- if (config.database)
27
- cfg.database = config.database;
28
- if (config.schema)
29
- cfg.schema = config.schema;
30
- const connection = new postgrejs_1.Connection(cfg);
31
- try {
32
- await connection.connect();
33
- return new pg_connection_js_1.PgConnection(connection);
34
- }
35
- catch (e) {
36
- await connection.close(0);
37
- throw e;
38
- }
39
- }
40
- }
41
- exports.PgAdapter = PgAdapter;
@@ -1,159 +0,0 @@
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 SqbDataTypToOIDMap = {
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],
23
- };
24
- class PgConnection {
25
- intlcon;
26
- constructor(conn) {
27
- this.intlcon = conn;
28
- }
29
- get sessionId() {
30
- return this.intlcon && this.intlcon.processID;
31
- }
32
- async close() {
33
- if (!this.intlcon)
34
- return;
35
- await this.intlcon.close(0);
36
- this.intlcon = undefined;
37
- }
38
- async reset() {
39
- return this.rollback();
40
- }
41
- async startTransaction() {
42
- if (!this.intlcon)
43
- throw new Error('Can not start transaction for a closed db session');
44
- await this.intlcon.startTransaction();
45
- }
46
- async commit() {
47
- if (!this.intlcon)
48
- throw new Error('Can not commit transaction for a closed db session');
49
- await this.intlcon.commit();
50
- }
51
- async rollback() {
52
- if (!this.intlcon)
53
- return;
54
- await this.intlcon.rollback();
55
- }
56
- async setSavepoint(savepoint) {
57
- if (!this.intlcon)
58
- throw new Error('Can not set savepoint for a closed db session');
59
- return this.intlcon.savepoint(savepoint);
60
- }
61
- async releaseSavepoint(savepoint) {
62
- if (!this.intlcon)
63
- throw new Error('Can not release savepoint for a closed db session');
64
- return this.intlcon.releaseSavepoint(savepoint);
65
- }
66
- async rollbackSavepoint(savepoint) {
67
- if (!this.intlcon)
68
- throw new Error('Can not rollback to a savepoint for a closed db session');
69
- return this.intlcon.rollbackToSavepoint(savepoint);
70
- }
71
- getInTransaction() {
72
- return !!(this.intlcon && this.intlcon.inTransaction);
73
- }
74
- async test() {
75
- if (!this.intlcon)
76
- throw new Error('DB session is closed');
77
- await this.intlcon.query('select 1');
78
- }
79
- async getSchema() {
80
- if (!this.intlcon)
81
- throw new Error('DB session is closed');
82
- const r = await this.intlcon.query('SHOW search_path');
83
- if (r && r.rows && r.rows[0])
84
- return r.rows[0][0];
85
- return '';
86
- }
87
- async setSchema(schema) {
88
- if (!this.intlcon)
89
- throw new Error('Can not set schema of a closed db session');
90
- await this.intlcon.execute('SET search_path TO ' + schema);
91
- }
92
- onGenerateQuery(request) {
93
- if (this.intlcon) {
94
- request.dialectVersion = this.intlcon.sessionParameters['server_version'];
95
- }
96
- }
97
- async execute(query) {
98
- if (!this.intlcon)
99
- throw new Error('Can not execute query with a closed db session');
100
- const params = query.params?.map((v, i) => {
101
- const paramOpts = Array.isArray(query.paramOptions)
102
- ? query.paramOptions[i]
103
- : undefined;
104
- if (v != null && paramOpts && paramOpts.dataType) {
105
- const oid = SqbDataTypToOIDMap[paramOpts.dataType]?.[paramOpts.isArray ? 1 : 0];
106
- if (oid)
107
- return new postgrejs_1.BindParam(oid, v);
108
- }
109
- return v;
110
- });
111
- const opts = {
112
- autoCommit: query.autoCommit,
113
- params,
114
- cursor: query.cursor,
115
- fetchCount: query.fetchRows,
116
- objectRows: query.objectRows,
117
- };
118
- if (query.fetchAsString) {
119
- const items = query.fetchAsString.reduce((a, v) => {
120
- const oid = SqbDataTypToOIDMap[v][0];
121
- if (oid)
122
- a.push(oid);
123
- return a;
124
- }, []);
125
- if (items.length)
126
- opts.fetchAsString = items;
127
- }
128
- const resp = await this.intlcon.query(query.sql, opts);
129
- const out = {};
130
- if (resp.fields)
131
- out.fields = this._convertFields(resp.fields);
132
- if (resp.rows)
133
- out.rows = resp.rows;
134
- if (resp.cursor)
135
- out.cursor = resp.cursor;
136
- if (resp.rowType)
137
- out.rowType = resp.rowType;
138
- if (resp.rowsAffected)
139
- out.rowsAffected = resp.rowsAffected;
140
- return out;
141
- }
142
- _convertFields(fields) {
143
- const result = [];
144
- for (let i = 0; i < fields.length; i++) {
145
- const v = fields[i];
146
- const o = {
147
- fieldName: v.fieldName,
148
- dataType: v.dataTypeName,
149
- elementDataType: v.elementDataTypeName,
150
- jsType: v.jsType,
151
- isArray: v.isArray,
152
- _inf: v,
153
- };
154
- result.push(o);
155
- }
156
- return result;
157
- }
158
- }
159
- exports.PgConnection = PgConnection;
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/types/index.d.cts DELETED
@@ -1,2 +0,0 @@
1
- import '@sqb/postgres-dialect';
2
- export * from './pg-adapter.js';
File without changes
File without changes
File without changes
File without changes
File without changes