postgrejs 2.12.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/CHANGELOG.md +814 -0
- package/LICENSE +21 -0
- package/README.md +200 -0
- package/cjs/connection/bind-param.js +10 -0
- package/cjs/connection/connection.js +279 -0
- package/cjs/connection/cursor.js +93 -0
- package/cjs/connection/intl-connection.js +243 -0
- package/cjs/connection/pool.js +226 -0
- package/cjs/connection/portal.js +148 -0
- package/cjs/connection/prepared-statement.js +217 -0
- package/cjs/constants.js +250 -0
- package/cjs/data-type-map.js +119 -0
- package/cjs/data-types/bool-type.js +27 -0
- package/cjs/data-types/box-type.js +52 -0
- package/cjs/data-types/bytea-type.js +29 -0
- package/cjs/data-types/char-type.js +27 -0
- package/cjs/data-types/circle-type.js +48 -0
- package/cjs/data-types/date-type.js +67 -0
- package/cjs/data-types/float4-type.js +25 -0
- package/cjs/data-types/float8-type.js +25 -0
- package/cjs/data-types/int2-type.js +26 -0
- package/cjs/data-types/int2-vector-type.js +38 -0
- package/cjs/data-types/int4-type.js +26 -0
- package/cjs/data-types/int8-type.js +31 -0
- package/cjs/data-types/json-type.js +38 -0
- package/cjs/data-types/jsonb-type.js +42 -0
- package/cjs/data-types/lseg-type.js +52 -0
- package/cjs/data-types/numeric-type.js +125 -0
- package/cjs/data-types/oid-type.js +32 -0
- package/cjs/data-types/point-type.js +39 -0
- package/cjs/data-types/time-type.js +54 -0
- package/cjs/data-types/timestamp-type.js +81 -0
- package/cjs/data-types/timestamptz-type.js +73 -0
- package/cjs/data-types/uuid-type.js +39 -0
- package/cjs/data-types/varchar-type.js +27 -0
- package/cjs/index.js +41 -0
- package/cjs/interfaces/command-result.js +2 -0
- package/cjs/interfaces/data-mapping-options.js +2 -0
- package/cjs/interfaces/data-type.js +2 -0
- package/cjs/interfaces/database-connection-params.js +2 -0
- package/cjs/interfaces/field-info.js +2 -0
- package/cjs/interfaces/query-options.js +2 -0
- package/cjs/interfaces/query-result.js +2 -0
- package/cjs/interfaces/script-execute-options.js +2 -0
- package/cjs/interfaces/script-result.js +2 -0
- package/cjs/interfaces/statement-prepare-options.js +2 -0
- package/cjs/package.json +3 -0
- package/cjs/protocol/backend.js +256 -0
- package/cjs/protocol/buffer-reader.js +78 -0
- package/cjs/protocol/database-error.js +17 -0
- package/cjs/protocol/frontend.js +218 -0
- package/cjs/protocol/pg-socket.js +345 -0
- package/cjs/protocol/protocol.js +71 -0
- package/cjs/protocol/sasl.js +108 -0
- package/cjs/protocol/smart-buffer.js +195 -0
- package/cjs/safe-event-emitter.js +17 -0
- package/cjs/types.js +2 -0
- package/cjs/util/array-calculatedim.js +19 -0
- package/cjs/util/bigint-methods.js +42 -0
- package/cjs/util/config-from-env.js +30 -0
- package/cjs/util/connection-config.js +65 -0
- package/cjs/util/convert-row-to-object.js +13 -0
- package/cjs/util/decode-binaryarray.js +39 -0
- package/cjs/util/encode-binaryarray.js +45 -0
- package/cjs/util/escape-literal.js +27 -0
- package/cjs/util/fast-parseint.js +32 -0
- package/cjs/util/get-parsers.js +42 -0
- package/cjs/util/parse-array.js +61 -0
- package/cjs/util/parse-datetime.js +38 -0
- package/cjs/util/parse-row.js +11 -0
- package/cjs/util/parse-time.js +29 -0
- package/cjs/util/stringify-arrayliteral.js +38 -0
- package/cjs/util/stringify-for-sql.js +30 -0
- package/cjs/util/wrap-row-description.js +35 -0
- package/esm/connection/bind-param.js +6 -0
- package/esm/connection/connection.js +275 -0
- package/esm/connection/cursor.js +86 -0
- package/esm/connection/intl-connection.js +238 -0
- package/esm/connection/pool.js +222 -0
- package/esm/connection/portal.js +144 -0
- package/esm/connection/prepared-statement.js +213 -0
- package/esm/constants.js +247 -0
- package/esm/data-type-map.js +115 -0
- package/esm/data-types/bool-type.js +24 -0
- package/esm/data-types/box-type.js +49 -0
- package/esm/data-types/bytea-type.js +23 -0
- package/esm/data-types/char-type.js +24 -0
- package/esm/data-types/circle-type.js +45 -0
- package/esm/data-types/date-type.js +64 -0
- package/esm/data-types/float4-type.js +22 -0
- package/esm/data-types/float8-type.js +22 -0
- package/esm/data-types/int2-type.js +23 -0
- package/esm/data-types/int2-vector-type.js +35 -0
- package/esm/data-types/int4-type.js +23 -0
- package/esm/data-types/int8-type.js +28 -0
- package/esm/data-types/json-type.js +35 -0
- package/esm/data-types/jsonb-type.js +39 -0
- package/esm/data-types/lseg-type.js +49 -0
- package/esm/data-types/numeric-type.js +121 -0
- package/esm/data-types/oid-type.js +29 -0
- package/esm/data-types/point-type.js +36 -0
- package/esm/data-types/time-type.js +51 -0
- package/esm/data-types/timestamp-type.js +78 -0
- package/esm/data-types/timestamptz-type.js +70 -0
- package/esm/data-types/uuid-type.js +36 -0
- package/esm/data-types/varchar-type.js +24 -0
- package/esm/index.js +25 -0
- package/esm/interfaces/command-result.js +1 -0
- package/esm/interfaces/data-mapping-options.js +1 -0
- package/esm/interfaces/data-type.js +1 -0
- package/esm/interfaces/database-connection-params.js +1 -0
- package/esm/interfaces/field-info.js +1 -0
- package/esm/interfaces/query-options.js +1 -0
- package/esm/interfaces/query-result.js +1 -0
- package/esm/interfaces/script-execute-options.js +1 -0
- package/esm/interfaces/script-result.js +1 -0
- package/esm/interfaces/statement-prepare-options.js +1 -0
- package/esm/protocol/backend.js +252 -0
- package/esm/protocol/buffer-reader.js +74 -0
- package/esm/protocol/database-error.js +13 -0
- package/esm/protocol/frontend.js +214 -0
- package/esm/protocol/pg-socket.js +338 -0
- package/esm/protocol/protocol.js +68 -0
- package/esm/protocol/sasl.js +102 -0
- package/esm/protocol/smart-buffer.js +168 -0
- package/esm/safe-event-emitter.js +13 -0
- package/esm/types.js +1 -0
- package/esm/util/array-calculatedim.js +15 -0
- package/esm/util/bigint-methods.js +37 -0
- package/esm/util/config-from-env.js +26 -0
- package/esm/util/connection-config.js +57 -0
- package/esm/util/convert-row-to-object.js +9 -0
- package/esm/util/decode-binaryarray.js +35 -0
- package/esm/util/encode-binaryarray.js +41 -0
- package/esm/util/escape-literal.js +23 -0
- package/esm/util/fast-parseint.js +28 -0
- package/esm/util/get-parsers.js +38 -0
- package/esm/util/parse-array.js +57 -0
- package/esm/util/parse-datetime.js +34 -0
- package/esm/util/parse-row.js +7 -0
- package/esm/util/parse-time.js +25 -0
- package/esm/util/stringify-arrayliteral.js +34 -0
- package/esm/util/stringify-for-sql.js +25 -0
- package/esm/util/wrap-row-description.js +31 -0
- package/package.json +54 -0
- package/typings/connection/bind-param.d.ts +6 -0
- package/typings/connection/connection.d.ts +110 -0
- package/typings/connection/cursor.d.ts +25 -0
- package/typings/connection/intl-connection.d.ts +40 -0
- package/typings/connection/pool.d.ts +52 -0
- package/typings/connection/portal.d.ts +23 -0
- package/typings/connection/prepared-statement.d.ts +27 -0
- package/typings/constants.d.ts +130 -0
- package/typings/data-type-map.d.ts +11 -0
- package/typings/data-types/bool-type.d.ts +3 -0
- package/typings/data-types/box-type.d.ts +3 -0
- package/typings/data-types/bytea-type.d.ts +3 -0
- package/typings/data-types/char-type.d.ts +3 -0
- package/typings/data-types/circle-type.d.ts +3 -0
- package/typings/data-types/date-type.d.ts +3 -0
- package/typings/data-types/float4-type.d.ts +3 -0
- package/typings/data-types/float8-type.d.ts +3 -0
- package/typings/data-types/int2-type.d.ts +3 -0
- package/typings/data-types/int2-vector-type.d.ts +3 -0
- package/typings/data-types/int4-type.d.ts +3 -0
- package/typings/data-types/int8-type.d.ts +3 -0
- package/typings/data-types/json-type.d.ts +3 -0
- package/typings/data-types/jsonb-type.d.ts +3 -0
- package/typings/data-types/lseg-type.d.ts +3 -0
- package/typings/data-types/numeric-type.d.ts +12 -0
- package/typings/data-types/oid-type.d.ts +4 -0
- package/typings/data-types/point-type.d.ts +3 -0
- package/typings/data-types/time-type.d.ts +3 -0
- package/typings/data-types/timestamp-type.d.ts +3 -0
- package/typings/data-types/timestamptz-type.d.ts +3 -0
- package/typings/data-types/uuid-type.d.ts +3 -0
- package/typings/data-types/varchar-type.d.ts +3 -0
- package/typings/index.d.ts +25 -0
- package/typings/interfaces/command-result.d.ts +28 -0
- package/typings/interfaces/data-mapping-options.d.ts +9 -0
- package/typings/interfaces/data-type.d.ts +31 -0
- package/typings/interfaces/database-connection-params.d.ts +38 -0
- package/typings/interfaces/field-info.d.ts +46 -0
- package/typings/interfaces/query-options.d.ts +46 -0
- package/typings/interfaces/query-result.d.ts +8 -0
- package/typings/interfaces/script-execute-options.d.ts +26 -0
- package/typings/interfaces/script-result.d.ts +15 -0
- package/typings/interfaces/statement-prepare-options.d.ts +13 -0
- package/typings/protocol/backend.d.ts +9 -0
- package/typings/protocol/buffer-reader.d.ts +18 -0
- package/typings/protocol/database-error.d.ts +20 -0
- package/typings/protocol/frontend.d.ts +59 -0
- package/typings/protocol/pg-socket.d.ts +51 -0
- package/typings/protocol/protocol.d.ts +180 -0
- package/typings/protocol/sasl.d.ts +13 -0
- package/typings/protocol/smart-buffer.d.ts +39 -0
- package/typings/safe-event-emitter.d.ts +5 -0
- package/typings/types.d.ts +15 -0
- package/typings/util/array-calculatedim.d.ts +1 -0
- package/typings/util/bigint-methods.d.ts +3 -0
- package/typings/util/config-from-env.d.ts +2 -0
- package/typings/util/connection-config.d.ts +3 -0
- package/typings/util/convert-row-to-object.d.ts +2 -0
- package/typings/util/decode-binaryarray.d.ts +4 -0
- package/typings/util/encode-binaryarray.d.ts +5 -0
- package/typings/util/escape-literal.d.ts +1 -0
- package/typings/util/fast-parseint.d.ts +1 -0
- package/typings/util/get-parsers.d.ts +4 -0
- package/typings/util/parse-array.d.ts +5 -0
- package/typings/util/parse-datetime.d.ts +1 -0
- package/typings/util/parse-row.d.ts +3 -0
- package/typings/util/parse-time.d.ts +3 -0
- package/typings/util/stringify-arrayliteral.d.ts +3 -0
- package/typings/util/stringify-for-sql.d.ts +4 -0
- package/typings/util/wrap-row-description.d.ts +5 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreparedStatement = void 0;
|
|
4
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
+
const constants_js_1 = require("../constants.js");
|
|
6
|
+
const data_type_map_js_1 = require("../data-type-map.js");
|
|
7
|
+
const protocol_js_1 = require("../protocol/protocol.js");
|
|
8
|
+
const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
|
|
9
|
+
const convert_row_to_object_js_1 = require("../util/convert-row-to-object.js");
|
|
10
|
+
const get_parsers_js_1 = require("../util/get-parsers.js");
|
|
11
|
+
const parse_row_js_1 = require("../util/parse-row.js");
|
|
12
|
+
const wrap_row_description_js_1 = require("../util/wrap-row-description.js");
|
|
13
|
+
const cursor_js_1 = require("./cursor.js");
|
|
14
|
+
const intl_connection_js_1 = require("./intl-connection.js");
|
|
15
|
+
const portal_js_1 = require("./portal.js");
|
|
16
|
+
let statementCounter = 0;
|
|
17
|
+
let portalCounter = 0;
|
|
18
|
+
class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
19
|
+
constructor(connection, sql, paramTypes) {
|
|
20
|
+
super();
|
|
21
|
+
this._sql = '';
|
|
22
|
+
this._name = '';
|
|
23
|
+
this._refCount = 0;
|
|
24
|
+
this._connection = connection;
|
|
25
|
+
this._name = 'S_' + ++statementCounter;
|
|
26
|
+
this._sql = sql;
|
|
27
|
+
this._paramTypes = paramTypes;
|
|
28
|
+
this._onErrorSavePoint = 'SP_' + Math.round(Math.random() * 100000000);
|
|
29
|
+
}
|
|
30
|
+
static async prepare(connection, sql, options) {
|
|
31
|
+
const intoCon = (0, intl_connection_js_1.getIntlConnection)(connection);
|
|
32
|
+
intoCon.assertConnected();
|
|
33
|
+
const socket = intoCon.socket;
|
|
34
|
+
const statement = new PreparedStatement(connection, sql, options?.paramTypes);
|
|
35
|
+
await intoCon.statementQueue
|
|
36
|
+
.enqueue(async () => {
|
|
37
|
+
intoCon.ref();
|
|
38
|
+
try {
|
|
39
|
+
socket.sendParseMessage({
|
|
40
|
+
statement: statement.name,
|
|
41
|
+
sql: statement.sql,
|
|
42
|
+
paramTypes: statement.paramTypes,
|
|
43
|
+
});
|
|
44
|
+
socket.sendFlushMessage();
|
|
45
|
+
try {
|
|
46
|
+
await socket.capture(async (code, msg, done) => {
|
|
47
|
+
if (code === protocol_js_1.Protocol.BackendMessageCode.ParseComplete)
|
|
48
|
+
done();
|
|
49
|
+
// May be Protocol.BackendMessageCode.NoticeResponse
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
socket.sendSyncMessage();
|
|
54
|
+
await socket.capture(async (code, msg, done) => {
|
|
55
|
+
if (code === protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery)
|
|
56
|
+
done();
|
|
57
|
+
// May be Protocol.BackendMessageCode.NoticeResponse
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
intoCon.unref();
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.toPromise();
|
|
66
|
+
statement._refCount = 1;
|
|
67
|
+
return statement;
|
|
68
|
+
}
|
|
69
|
+
get connection() {
|
|
70
|
+
return this._connection;
|
|
71
|
+
}
|
|
72
|
+
get name() {
|
|
73
|
+
return this._name;
|
|
74
|
+
}
|
|
75
|
+
get sql() {
|
|
76
|
+
return this._sql;
|
|
77
|
+
}
|
|
78
|
+
get paramTypes() {
|
|
79
|
+
return this._paramTypes;
|
|
80
|
+
}
|
|
81
|
+
async execute(options = {}) {
|
|
82
|
+
const intlCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
|
|
83
|
+
const transactionCommand = this.sql.match(/^(\bBEGIN\b|\bCOMMIT\b|\bSTART\b|\bROLLBACK|SAVEPOINT|RELEASE\b)/i);
|
|
84
|
+
let beginFirst = false;
|
|
85
|
+
let commitLast = false;
|
|
86
|
+
if (!transactionCommand) {
|
|
87
|
+
if (!intlCon.inTransaction &&
|
|
88
|
+
(options?.autoCommit != null ? options?.autoCommit : intlCon.config.autoCommit) === false) {
|
|
89
|
+
beginFirst = true;
|
|
90
|
+
}
|
|
91
|
+
if (intlCon.inTransaction && options?.autoCommit)
|
|
92
|
+
commitLast = true;
|
|
93
|
+
}
|
|
94
|
+
if (beginFirst)
|
|
95
|
+
await intlCon.execute('BEGIN');
|
|
96
|
+
const rollbackOnError = !transactionCommand &&
|
|
97
|
+
(options?.rollbackOnError != null
|
|
98
|
+
? options.rollbackOnError
|
|
99
|
+
: (0, putil_varhelpers_1.coerceToBoolean)(intlCon.config.rollbackOnError, true));
|
|
100
|
+
if (intlCon.inTransaction && rollbackOnError)
|
|
101
|
+
await intlCon.execute('SAVEPOINT ' + this._onErrorSavePoint);
|
|
102
|
+
try {
|
|
103
|
+
const result = await intlCon.statementQueue.enqueue(() => this._execute(options)).toPromise();
|
|
104
|
+
if (commitLast)
|
|
105
|
+
await intlCon.execute('COMMIT');
|
|
106
|
+
else if (intlCon.inTransaction && rollbackOnError)
|
|
107
|
+
await intlCon.execute('RELEASE ' + this._onErrorSavePoint + ';');
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
if (intlCon.inTransaction && rollbackOnError)
|
|
112
|
+
await intlCon.execute('ROLLBACK TO ' + this._onErrorSavePoint + ';');
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async close() {
|
|
117
|
+
--this._refCount;
|
|
118
|
+
if (this._refCount > 0)
|
|
119
|
+
return;
|
|
120
|
+
const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
|
|
121
|
+
await intoCon.statementQueue.enqueue(() => this._close()).toPromise();
|
|
122
|
+
}
|
|
123
|
+
async cancel() {
|
|
124
|
+
throw new Error('Not implemented yet');
|
|
125
|
+
}
|
|
126
|
+
async _execute(options = {}) {
|
|
127
|
+
let portal;
|
|
128
|
+
const intlCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
|
|
129
|
+
intlCon.ref();
|
|
130
|
+
try {
|
|
131
|
+
const result = { command: undefined };
|
|
132
|
+
const startTime = Date.now();
|
|
133
|
+
const t = Date.now();
|
|
134
|
+
// Create portal
|
|
135
|
+
const portalName = 'P_' + ++portalCounter;
|
|
136
|
+
portal = new portal_js_1.Portal(this, portalName);
|
|
137
|
+
await portal.bind(options.params, options);
|
|
138
|
+
const fields = await portal.retrieveFields();
|
|
139
|
+
const typeMap = options.typeMap || data_type_map_js_1.GlobalTypeMap;
|
|
140
|
+
let parsers;
|
|
141
|
+
let resultFields;
|
|
142
|
+
if (fields) {
|
|
143
|
+
parsers = (0, get_parsers_js_1.getParsers)(typeMap, fields);
|
|
144
|
+
resultFields = (0, wrap_row_description_js_1.wrapRowDescription)(typeMap, fields, options.columnFormat || constants_js_1.DEFAULT_COLUMN_FORMAT);
|
|
145
|
+
result.fields = resultFields;
|
|
146
|
+
result.rowType = options.objectRows ? 'object' : 'array';
|
|
147
|
+
if (options.cursor) {
|
|
148
|
+
result.cursor = new cursor_js_1.Cursor(this, portal, resultFields, parsers, options);
|
|
149
|
+
this._refCount++;
|
|
150
|
+
portal = undefined;
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const executeResult = await portal.execute(options.fetchCount);
|
|
155
|
+
result.executeTime = Date.now() - t;
|
|
156
|
+
if (executeResult.command)
|
|
157
|
+
result.command = executeResult.command;
|
|
158
|
+
if (resultFields && parsers && executeResult.rows) {
|
|
159
|
+
if (!result.command)
|
|
160
|
+
result.command = 'SELECT';
|
|
161
|
+
const rows = (result.rows = executeResult.rows);
|
|
162
|
+
const l = rows.length;
|
|
163
|
+
let row;
|
|
164
|
+
for (let i = 0; i < l; i++) {
|
|
165
|
+
row = rows[i];
|
|
166
|
+
(0, parse_row_js_1.parseRow)(parsers, row, options);
|
|
167
|
+
if (options.objectRows) {
|
|
168
|
+
rows[i] = (0, convert_row_to_object_js_1.convertRowToObject)(resultFields, row);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE')
|
|
173
|
+
result.rowsAffected = executeResult.rowCount;
|
|
174
|
+
result.executeTime = Date.now() - startTime;
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
intlCon.unref();
|
|
179
|
+
if (portal)
|
|
180
|
+
await portal.close();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async _close() {
|
|
184
|
+
if (--this._refCount > 0)
|
|
185
|
+
return;
|
|
186
|
+
const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
|
|
187
|
+
intoCon.ref();
|
|
188
|
+
try {
|
|
189
|
+
const socket = intoCon.socket;
|
|
190
|
+
socket.sendCloseMessage({ type: 'S', name: this.name });
|
|
191
|
+
socket.sendSyncMessage();
|
|
192
|
+
await socket.capture(async (code, msg, done) => {
|
|
193
|
+
switch (code) {
|
|
194
|
+
case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
|
|
195
|
+
this.emit('notice', msg);
|
|
196
|
+
break;
|
|
197
|
+
case protocol_js_1.Protocol.BackendMessageCode.CloseComplete:
|
|
198
|
+
break;
|
|
199
|
+
case protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery:
|
|
200
|
+
intoCon.transactionStatus = msg.status;
|
|
201
|
+
done();
|
|
202
|
+
break;
|
|
203
|
+
default:
|
|
204
|
+
done(new Error(`Server returned unexpected response message (0x${code.toString(16)})`));
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
intoCon.unref();
|
|
210
|
+
}
|
|
211
|
+
this.emit('close');
|
|
212
|
+
}
|
|
213
|
+
[Symbol.asyncDispose]() {
|
|
214
|
+
return this.close();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.PreparedStatement = PreparedStatement;
|
package/cjs/constants.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataTypeNames = exports.DataTypeOIDs = exports.ConnectionState = exports.DEFAULT_COLUMN_FORMAT = exports.DataFormat = void 0;
|
|
4
|
+
const protocol_js_1 = require("./protocol/protocol.js");
|
|
5
|
+
var DataFormat = protocol_js_1.Protocol.DataFormat;
|
|
6
|
+
exports.DataFormat = DataFormat;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
Symbol.asyncDispose ?? (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
|
|
9
|
+
exports.DEFAULT_COLUMN_FORMAT = DataFormat.binary;
|
|
10
|
+
var ConnectionState;
|
|
11
|
+
(function (ConnectionState) {
|
|
12
|
+
ConnectionState[ConnectionState["CLOSED"] = 0] = "CLOSED";
|
|
13
|
+
ConnectionState[ConnectionState["CONNECTING"] = 1] = "CONNECTING";
|
|
14
|
+
ConnectionState[ConnectionState["AUTHORIZING"] = 3] = "AUTHORIZING";
|
|
15
|
+
ConnectionState[ConnectionState["READY"] = 2] = "READY";
|
|
16
|
+
ConnectionState[ConnectionState["CLOSING"] = 10] = "CLOSING";
|
|
17
|
+
})(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
|
|
18
|
+
exports.DataTypeOIDs = {
|
|
19
|
+
bool: 16,
|
|
20
|
+
bytea: 17,
|
|
21
|
+
char: 18,
|
|
22
|
+
name: 19,
|
|
23
|
+
int8: 20,
|
|
24
|
+
int2: 21,
|
|
25
|
+
int2vector: 22,
|
|
26
|
+
int4: 23,
|
|
27
|
+
regproc: 24,
|
|
28
|
+
text: 25,
|
|
29
|
+
oid: 26,
|
|
30
|
+
tid: 27,
|
|
31
|
+
xid: 28,
|
|
32
|
+
cid: 29,
|
|
33
|
+
oidvector: 30,
|
|
34
|
+
json: 114,
|
|
35
|
+
xml: 142,
|
|
36
|
+
point: 600,
|
|
37
|
+
lseg: 601,
|
|
38
|
+
path: 602,
|
|
39
|
+
box: 603,
|
|
40
|
+
polygon: 604,
|
|
41
|
+
line: 628,
|
|
42
|
+
cidr: 650,
|
|
43
|
+
float4: 700,
|
|
44
|
+
float8: 701,
|
|
45
|
+
unknown: 705,
|
|
46
|
+
circle: 718,
|
|
47
|
+
macaddr8: 774,
|
|
48
|
+
money: 790,
|
|
49
|
+
macaddr: 829,
|
|
50
|
+
inet: 869,
|
|
51
|
+
bpchar: 1042,
|
|
52
|
+
varchar: 1043,
|
|
53
|
+
date: 1082,
|
|
54
|
+
time: 1083,
|
|
55
|
+
timestamp: 1114,
|
|
56
|
+
timestamptz: 1184,
|
|
57
|
+
interval: 1186,
|
|
58
|
+
timetz: 1266,
|
|
59
|
+
bit: 1560,
|
|
60
|
+
varbit: 1562,
|
|
61
|
+
numeric: 1700,
|
|
62
|
+
refcursor: 1790,
|
|
63
|
+
regprocedure: 2202,
|
|
64
|
+
regoper: 2203,
|
|
65
|
+
regoperator: 2204,
|
|
66
|
+
regclass: 2205,
|
|
67
|
+
regtype: 2206,
|
|
68
|
+
record: 2249,
|
|
69
|
+
cstring: 2275,
|
|
70
|
+
any: 2276,
|
|
71
|
+
anyarray: 2277,
|
|
72
|
+
void: 2278,
|
|
73
|
+
trigger: 2279,
|
|
74
|
+
// eslint-disable-next-line camelcase
|
|
75
|
+
language_handler: 2280,
|
|
76
|
+
internal: 2281,
|
|
77
|
+
anyelement: 2283,
|
|
78
|
+
anynonarray: 2776,
|
|
79
|
+
uuid: 2950,
|
|
80
|
+
jsonb: 3802,
|
|
81
|
+
anyrange: 3831,
|
|
82
|
+
int4range: 3904,
|
|
83
|
+
numrange: 3906,
|
|
84
|
+
tsrange: 3908,
|
|
85
|
+
rstzrange: 3910,
|
|
86
|
+
daterange: 3912,
|
|
87
|
+
int8range: 3926,
|
|
88
|
+
_xml: 143,
|
|
89
|
+
_json: 199,
|
|
90
|
+
_xid8: 271,
|
|
91
|
+
_line: 629,
|
|
92
|
+
_cidr: 651,
|
|
93
|
+
_circle: 719,
|
|
94
|
+
_macaddr8: 775,
|
|
95
|
+
_money: 791,
|
|
96
|
+
_bool: 1000,
|
|
97
|
+
_bytea: 1001,
|
|
98
|
+
_char: 1002,
|
|
99
|
+
_name: 1003,
|
|
100
|
+
_int2: 1005,
|
|
101
|
+
_int2vector: 1006,
|
|
102
|
+
_int4: 1007,
|
|
103
|
+
_regproc: 1008,
|
|
104
|
+
_text: 1009,
|
|
105
|
+
_tid: 1010,
|
|
106
|
+
_xid: 1011,
|
|
107
|
+
_cid: 1012,
|
|
108
|
+
_oidvector: 1013,
|
|
109
|
+
_bpchar: 1014,
|
|
110
|
+
_varchar: 1015,
|
|
111
|
+
_int8: 1016,
|
|
112
|
+
_point: 1017,
|
|
113
|
+
_lseg: 1018,
|
|
114
|
+
_path: 1019,
|
|
115
|
+
_box: 1020,
|
|
116
|
+
_float4: 1021,
|
|
117
|
+
_float8: 1022,
|
|
118
|
+
_polygon: 1027,
|
|
119
|
+
_oid: 1028,
|
|
120
|
+
_macaddr: 1040,
|
|
121
|
+
_inet: 1041,
|
|
122
|
+
_timestamp: 1115,
|
|
123
|
+
_date: 1182,
|
|
124
|
+
_time: 1183,
|
|
125
|
+
_timestamptz: 1185,
|
|
126
|
+
_interval: 1187,
|
|
127
|
+
_numeric: 1231,
|
|
128
|
+
_cstring: 1263,
|
|
129
|
+
_timetz: 1270,
|
|
130
|
+
_bit: 1561,
|
|
131
|
+
_varbit: 1563,
|
|
132
|
+
_uuid: 2951,
|
|
133
|
+
_jsonb: 3807,
|
|
134
|
+
};
|
|
135
|
+
exports.DataTypeNames = {
|
|
136
|
+
[exports.DataTypeOIDs.bool]: 'bool',
|
|
137
|
+
[exports.DataTypeOIDs.bytea]: 'bytea',
|
|
138
|
+
[exports.DataTypeOIDs.char]: 'char',
|
|
139
|
+
[exports.DataTypeOIDs.name]: 'name',
|
|
140
|
+
[exports.DataTypeOIDs.int8]: 'int8',
|
|
141
|
+
[exports.DataTypeOIDs.int2]: 'int2',
|
|
142
|
+
[exports.DataTypeOIDs.int2vector]: 'int2vector',
|
|
143
|
+
[exports.DataTypeOIDs.int4]: 'int4',
|
|
144
|
+
[exports.DataTypeOIDs.regproc]: 'regproc',
|
|
145
|
+
[exports.DataTypeOIDs.text]: 'text',
|
|
146
|
+
[exports.DataTypeOIDs.oid]: 'oid',
|
|
147
|
+
[exports.DataTypeOIDs.tid]: 'tid',
|
|
148
|
+
[exports.DataTypeOIDs.xid]: 'xid',
|
|
149
|
+
[exports.DataTypeOIDs.cid]: 'cid',
|
|
150
|
+
[exports.DataTypeOIDs.oidvector]: 'oidvector',
|
|
151
|
+
[exports.DataTypeOIDs.json]: 'json',
|
|
152
|
+
[exports.DataTypeOIDs.xml]: 'xml',
|
|
153
|
+
[exports.DataTypeOIDs.point]: 'point',
|
|
154
|
+
[exports.DataTypeOIDs.lseg]: 'lseg',
|
|
155
|
+
[exports.DataTypeOIDs.path]: 'path',
|
|
156
|
+
[exports.DataTypeOIDs.box]: 'box',
|
|
157
|
+
[exports.DataTypeOIDs.polygon]: 'polygon',
|
|
158
|
+
[exports.DataTypeOIDs.line]: 'line',
|
|
159
|
+
[exports.DataTypeOIDs.cidr]: 'cidr',
|
|
160
|
+
[exports.DataTypeOIDs.float4]: 'float4',
|
|
161
|
+
[exports.DataTypeOIDs.float8]: 'float8',
|
|
162
|
+
[exports.DataTypeOIDs.unknown]: 'unknown',
|
|
163
|
+
[exports.DataTypeOIDs.circle]: 'circle',
|
|
164
|
+
[exports.DataTypeOIDs.macaddr8]: 'macaddr8',
|
|
165
|
+
[exports.DataTypeOIDs.money]: 'money',
|
|
166
|
+
[exports.DataTypeOIDs.macaddr]: 'macaddr',
|
|
167
|
+
[exports.DataTypeOIDs.inet]: 'inet',
|
|
168
|
+
[exports.DataTypeOIDs.bpchar]: 'bpchar',
|
|
169
|
+
[exports.DataTypeOIDs.varchar]: 'varchar',
|
|
170
|
+
[exports.DataTypeOIDs.date]: 'date',
|
|
171
|
+
[exports.DataTypeOIDs.time]: 'time',
|
|
172
|
+
[exports.DataTypeOIDs.timestamp]: 'timestamp',
|
|
173
|
+
[exports.DataTypeOIDs.timestamptz]: 'timestamptz',
|
|
174
|
+
[exports.DataTypeOIDs.interval]: 'interval',
|
|
175
|
+
[exports.DataTypeOIDs.timetz]: 'timetz',
|
|
176
|
+
[exports.DataTypeOIDs.bit]: 'bit',
|
|
177
|
+
[exports.DataTypeOIDs.varbit]: 'varbit',
|
|
178
|
+
[exports.DataTypeOIDs.numeric]: 'numeric',
|
|
179
|
+
[exports.DataTypeOIDs.refcursor]: 'refcursor',
|
|
180
|
+
[exports.DataTypeOIDs.regprocedure]: 'regprocedure',
|
|
181
|
+
[exports.DataTypeOIDs.regoper]: 'regoper',
|
|
182
|
+
[exports.DataTypeOIDs.regoperator]: 'regoperator',
|
|
183
|
+
[exports.DataTypeOIDs.regclass]: 'regclass',
|
|
184
|
+
[exports.DataTypeOIDs.regtype]: 'regtype',
|
|
185
|
+
[exports.DataTypeOIDs.record]: 'record',
|
|
186
|
+
[exports.DataTypeOIDs.cstring]: 'cstring',
|
|
187
|
+
[exports.DataTypeOIDs.any]: 'any',
|
|
188
|
+
[exports.DataTypeOIDs.anyarray]: 'anyarray',
|
|
189
|
+
[exports.DataTypeOIDs.void]: 'void',
|
|
190
|
+
[exports.DataTypeOIDs.trigger]: 'trigger',
|
|
191
|
+
[exports.DataTypeOIDs.language_handler]: 'language_handler',
|
|
192
|
+
[exports.DataTypeOIDs.internal]: 'internal',
|
|
193
|
+
[exports.DataTypeOIDs.anyelement]: 'anyelement',
|
|
194
|
+
[exports.DataTypeOIDs.anynonarray]: 'anynonarray',
|
|
195
|
+
[exports.DataTypeOIDs.uuid]: 'uuid',
|
|
196
|
+
[exports.DataTypeOIDs.jsonb]: 'jsonb',
|
|
197
|
+
[exports.DataTypeOIDs.anyrange]: 'anyrange',
|
|
198
|
+
[exports.DataTypeOIDs.int4range]: 'int4range',
|
|
199
|
+
[exports.DataTypeOIDs.numrange]: 'numrange',
|
|
200
|
+
[exports.DataTypeOIDs.tsrange]: 'tsrange',
|
|
201
|
+
[exports.DataTypeOIDs.rstzrange]: 'rstzrange',
|
|
202
|
+
[exports.DataTypeOIDs.daterange]: 'daterange',
|
|
203
|
+
[exports.DataTypeOIDs.int8range]: 'int8range',
|
|
204
|
+
[exports.DataTypeOIDs._xml]: '_xml',
|
|
205
|
+
[exports.DataTypeOIDs._json]: '_json',
|
|
206
|
+
[exports.DataTypeOIDs._xid8]: '_xid8',
|
|
207
|
+
[exports.DataTypeOIDs._line]: '_line',
|
|
208
|
+
[exports.DataTypeOIDs._cidr]: '_cidr',
|
|
209
|
+
[exports.DataTypeOIDs._circle]: '_circle',
|
|
210
|
+
[exports.DataTypeOIDs._macaddr8]: '_macaddr8',
|
|
211
|
+
[exports.DataTypeOIDs._money]: '_money',
|
|
212
|
+
[exports.DataTypeOIDs._bool]: '_bool',
|
|
213
|
+
[exports.DataTypeOIDs._bytea]: '_bytea',
|
|
214
|
+
[exports.DataTypeOIDs._char]: '_char',
|
|
215
|
+
[exports.DataTypeOIDs._name]: '_name',
|
|
216
|
+
[exports.DataTypeOIDs._int2]: '_int2',
|
|
217
|
+
[exports.DataTypeOIDs._int2vector]: '_int2vector',
|
|
218
|
+
[exports.DataTypeOIDs._int4]: '_int4',
|
|
219
|
+
[exports.DataTypeOIDs._regproc]: '_regproc',
|
|
220
|
+
[exports.DataTypeOIDs._text]: '_text',
|
|
221
|
+
[exports.DataTypeOIDs._tid]: '_tid',
|
|
222
|
+
[exports.DataTypeOIDs._xid]: '_xid',
|
|
223
|
+
[exports.DataTypeOIDs._cid]: '_cid',
|
|
224
|
+
[exports.DataTypeOIDs._oidvector]: '_oidvector',
|
|
225
|
+
[exports.DataTypeOIDs._bpchar]: '_bpchar',
|
|
226
|
+
[exports.DataTypeOIDs._varchar]: '_varchar',
|
|
227
|
+
[exports.DataTypeOIDs._int8]: '_int8',
|
|
228
|
+
[exports.DataTypeOIDs._point]: '_point',
|
|
229
|
+
[exports.DataTypeOIDs._lseg]: '_lseg',
|
|
230
|
+
[exports.DataTypeOIDs._path]: '_path',
|
|
231
|
+
[exports.DataTypeOIDs._box]: '_box',
|
|
232
|
+
[exports.DataTypeOIDs._float4]: '_float4',
|
|
233
|
+
[exports.DataTypeOIDs._float8]: '_float8',
|
|
234
|
+
[exports.DataTypeOIDs._polygon]: '_polygon',
|
|
235
|
+
[exports.DataTypeOIDs._oid]: '_oid',
|
|
236
|
+
[exports.DataTypeOIDs._macaddr]: '_macaddr',
|
|
237
|
+
[exports.DataTypeOIDs._inet]: '_inet',
|
|
238
|
+
[exports.DataTypeOIDs._timestamp]: '_timestamp',
|
|
239
|
+
[exports.DataTypeOIDs._date]: '_date',
|
|
240
|
+
[exports.DataTypeOIDs._time]: '_time',
|
|
241
|
+
[exports.DataTypeOIDs._timestamptz]: '_timestamptz',
|
|
242
|
+
[exports.DataTypeOIDs._interval]: '_interval',
|
|
243
|
+
[exports.DataTypeOIDs._numeric]: '_numeric',
|
|
244
|
+
[exports.DataTypeOIDs._cstring]: '_cstring',
|
|
245
|
+
[exports.DataTypeOIDs._timetz]: '_timetz',
|
|
246
|
+
[exports.DataTypeOIDs._bit]: '_bit',
|
|
247
|
+
[exports.DataTypeOIDs._varbit]: '_varbit',
|
|
248
|
+
[exports.DataTypeOIDs._uuid]: '_uuid',
|
|
249
|
+
[exports.DataTypeOIDs._jsonb]: '_jsonb',
|
|
250
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalTypeMap = exports.DataTypeMap = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
const bool_type_js_1 = require("./data-types/bool-type.js");
|
|
6
|
+
const box_type_js_1 = require("./data-types/box-type.js");
|
|
7
|
+
const bytea_type_js_1 = require("./data-types/bytea-type.js");
|
|
8
|
+
const char_type_js_1 = require("./data-types/char-type.js");
|
|
9
|
+
const circle_type_js_1 = require("./data-types/circle-type.js");
|
|
10
|
+
const date_type_js_1 = require("./data-types/date-type.js");
|
|
11
|
+
const float4_type_js_1 = require("./data-types/float4-type.js");
|
|
12
|
+
const float8_type_js_1 = require("./data-types/float8-type.js");
|
|
13
|
+
const int2_type_js_1 = require("./data-types/int2-type.js");
|
|
14
|
+
const int2_vector_type_js_1 = require("./data-types/int2-vector-type.js");
|
|
15
|
+
const int4_type_js_1 = require("./data-types/int4-type.js");
|
|
16
|
+
const int8_type_js_1 = require("./data-types/int8-type.js");
|
|
17
|
+
const json_type_js_1 = require("./data-types/json-type.js");
|
|
18
|
+
const jsonb_type_js_1 = require("./data-types/jsonb-type.js");
|
|
19
|
+
const lseg_type_js_1 = require("./data-types/lseg-type.js");
|
|
20
|
+
const numeric_type_js_1 = require("./data-types/numeric-type.js");
|
|
21
|
+
const oid_type_js_1 = require("./data-types/oid-type.js");
|
|
22
|
+
const point_type_js_1 = require("./data-types/point-type.js");
|
|
23
|
+
const time_type_js_1 = require("./data-types/time-type.js");
|
|
24
|
+
const timestamp_type_js_1 = require("./data-types/timestamp-type.js");
|
|
25
|
+
const timestamptz_type_js_1 = require("./data-types/timestamptz-type.js");
|
|
26
|
+
const uuid_type_js_1 = require("./data-types/uuid-type.js");
|
|
27
|
+
const varchar_type_js_1 = require("./data-types/varchar-type.js");
|
|
28
|
+
class DataTypeMap {
|
|
29
|
+
constructor(other) {
|
|
30
|
+
this._itemsByOID = {};
|
|
31
|
+
this._items = [];
|
|
32
|
+
if (other instanceof DataTypeMap)
|
|
33
|
+
Object.assign(this._items, other._items);
|
|
34
|
+
}
|
|
35
|
+
get(oid) {
|
|
36
|
+
return this._itemsByOID[oid];
|
|
37
|
+
}
|
|
38
|
+
register(dataTypes) {
|
|
39
|
+
dataTypes = Array.isArray(dataTypes) ? dataTypes : [dataTypes];
|
|
40
|
+
for (const t of dataTypes) {
|
|
41
|
+
this._itemsByOID[t.oid] = t;
|
|
42
|
+
const i = this._items.findIndex(tt => tt.oid === t.oid);
|
|
43
|
+
if (i >= 0)
|
|
44
|
+
this._items[i] = t;
|
|
45
|
+
else
|
|
46
|
+
this._items.push(t);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
determine(value) {
|
|
50
|
+
if (value == null)
|
|
51
|
+
return constants_js_1.DataTypeOIDs.unknown;
|
|
52
|
+
const valueIsArray = Array.isArray(value);
|
|
53
|
+
let i;
|
|
54
|
+
let t;
|
|
55
|
+
for (i = this._items.length - 1; i >= 0; i--) {
|
|
56
|
+
t = this._items[i];
|
|
57
|
+
if (valueIsArray) {
|
|
58
|
+
if (t.elementsOID && t.isType(value[0]))
|
|
59
|
+
return t.oid;
|
|
60
|
+
}
|
|
61
|
+
else if (!t.elementsOID && t.isType(value))
|
|
62
|
+
return t.oid;
|
|
63
|
+
}
|
|
64
|
+
return constants_js_1.DataTypeOIDs.unknown;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.DataTypeMap = DataTypeMap;
|
|
68
|
+
exports.GlobalTypeMap = new DataTypeMap();
|
|
69
|
+
exports.GlobalTypeMap.register([oid_type_js_1.OidType, oid_type_js_1.VectorOidType, oid_type_js_1.ArrayOidType]);
|
|
70
|
+
exports.GlobalTypeMap.register([jsonb_type_js_1.JsonbType, jsonb_type_js_1.ArrayJsonbType]);
|
|
71
|
+
exports.GlobalTypeMap.register([json_type_js_1.JsonType, json_type_js_1.ArrayJsonType]);
|
|
72
|
+
exports.GlobalTypeMap.register([bool_type_js_1.BoolType, bool_type_js_1.ArrayBoolType]);
|
|
73
|
+
exports.GlobalTypeMap.register([numeric_type_js_1.NumericType, numeric_type_js_1.ArrayNumericType]);
|
|
74
|
+
exports.GlobalTypeMap.register([float4_type_js_1.Float4Type, float4_type_js_1.ArrayFloat4Type]);
|
|
75
|
+
exports.GlobalTypeMap.register([float8_type_js_1.Float8Type, float8_type_js_1.ArrayFloat8Type]);
|
|
76
|
+
exports.GlobalTypeMap.register([int2_type_js_1.Int2Type, int2_type_js_1.ArrayInt2Type]);
|
|
77
|
+
exports.GlobalTypeMap.register([int4_type_js_1.Int4Type, int4_type_js_1.ArrayInt4Type]);
|
|
78
|
+
exports.GlobalTypeMap.register([int8_type_js_1.Int8Type, int8_type_js_1.ArrayInt8Type]);
|
|
79
|
+
exports.GlobalTypeMap.register([bytea_type_js_1.ByteaType, bytea_type_js_1.ArrayByteaType]);
|
|
80
|
+
exports.GlobalTypeMap.register([circle_type_js_1.CircleType, circle_type_js_1.ArrayCircleType]);
|
|
81
|
+
exports.GlobalTypeMap.register([point_type_js_1.PointType, point_type_js_1.ArrayPointType]);
|
|
82
|
+
exports.GlobalTypeMap.register([lseg_type_js_1.LsegType, lseg_type_js_1.ArrayLsegType]);
|
|
83
|
+
exports.GlobalTypeMap.register([box_type_js_1.BoxType, box_type_js_1.ArrayBoxType]);
|
|
84
|
+
exports.GlobalTypeMap.register([int2_vector_type_js_1.Int2VectorType, int2_vector_type_js_1.ArrayInt2VectorType]);
|
|
85
|
+
exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'bpchar', oid: constants_js_1.DataTypeOIDs.bpchar });
|
|
86
|
+
exports.GlobalTypeMap.register({
|
|
87
|
+
...varchar_type_js_1.ArrayVarcharType,
|
|
88
|
+
name: '_bpchar',
|
|
89
|
+
oid: constants_js_1.DataTypeOIDs._bpchar,
|
|
90
|
+
elementsOID: constants_js_1.DataTypeOIDs.bpchar,
|
|
91
|
+
});
|
|
92
|
+
exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'name', oid: constants_js_1.DataTypeOIDs.name });
|
|
93
|
+
exports.GlobalTypeMap.register({
|
|
94
|
+
...varchar_type_js_1.ArrayVarcharType,
|
|
95
|
+
name: '_name',
|
|
96
|
+
oid: constants_js_1.DataTypeOIDs._name,
|
|
97
|
+
elementsOID: constants_js_1.DataTypeOIDs.name,
|
|
98
|
+
});
|
|
99
|
+
exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'text', oid: constants_js_1.DataTypeOIDs.text });
|
|
100
|
+
exports.GlobalTypeMap.register({
|
|
101
|
+
...varchar_type_js_1.ArrayVarcharType,
|
|
102
|
+
name: '_text',
|
|
103
|
+
oid: constants_js_1.DataTypeOIDs._text,
|
|
104
|
+
elementsOID: constants_js_1.DataTypeOIDs.text,
|
|
105
|
+
});
|
|
106
|
+
exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'xml', oid: constants_js_1.DataTypeOIDs.xml });
|
|
107
|
+
exports.GlobalTypeMap.register({
|
|
108
|
+
...varchar_type_js_1.ArrayVarcharType,
|
|
109
|
+
name: '_xml',
|
|
110
|
+
oid: constants_js_1.DataTypeOIDs._xml,
|
|
111
|
+
elementsOID: constants_js_1.DataTypeOIDs.xml,
|
|
112
|
+
});
|
|
113
|
+
exports.GlobalTypeMap.register([varchar_type_js_1.VarcharType, varchar_type_js_1.ArrayVarcharType]);
|
|
114
|
+
exports.GlobalTypeMap.register([uuid_type_js_1.UuidType, uuid_type_js_1.ArrayUuidType]);
|
|
115
|
+
exports.GlobalTypeMap.register([char_type_js_1.CharType, char_type_js_1.ArrayCharType]);
|
|
116
|
+
exports.GlobalTypeMap.register([timestamptz_type_js_1.TimestamptzType, timestamptz_type_js_1.ArrayTimestamptzType]);
|
|
117
|
+
exports.GlobalTypeMap.register([time_type_js_1.TimeType, time_type_js_1.ArrayTimeType]);
|
|
118
|
+
exports.GlobalTypeMap.register([date_type_js_1.DateType, date_type_js_1.ArrayDateType]);
|
|
119
|
+
exports.GlobalTypeMap.register([timestamp_type_js_1.TimestampType, timestamp_type_js_1.ArrayTimestampType]);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayBoolType = exports.BoolType = void 0;
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
5
|
+
exports.BoolType = {
|
|
6
|
+
name: 'bool',
|
|
7
|
+
oid: constants_js_1.DataTypeOIDs.bool,
|
|
8
|
+
jsType: 'boolean',
|
|
9
|
+
parseBinary(v) {
|
|
10
|
+
return !!v.readUInt8();
|
|
11
|
+
},
|
|
12
|
+
encodeBinary(buf, v) {
|
|
13
|
+
buf.writeInt8(v ? 1 : 0);
|
|
14
|
+
},
|
|
15
|
+
parseText(v) {
|
|
16
|
+
return v === 'TRUE' || v === 't' || v === 'true' || v === 'y' || v === 'yes' || v === 'on' || v === '1';
|
|
17
|
+
},
|
|
18
|
+
isType(v) {
|
|
19
|
+
return typeof v === 'boolean';
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
exports.ArrayBoolType = {
|
|
23
|
+
...exports.BoolType,
|
|
24
|
+
name: '_bool',
|
|
25
|
+
oid: constants_js_1.DataTypeOIDs._bool,
|
|
26
|
+
elementsOID: constants_js_1.DataTypeOIDs.bool,
|
|
27
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayBoxType = exports.BoxType = void 0;
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
5
|
+
const BOX_PATTERN1 = /^\( *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *\)$/;
|
|
6
|
+
const BOX_PATTERN2 = /^\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\)$/;
|
|
7
|
+
const BOX_PATTERN3 = /^(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*)$/;
|
|
8
|
+
exports.BoxType = {
|
|
9
|
+
name: 'box',
|
|
10
|
+
oid: constants_js_1.DataTypeOIDs.box,
|
|
11
|
+
jsType: 'object',
|
|
12
|
+
arraySeparator: ';',
|
|
13
|
+
parseBinary(v) {
|
|
14
|
+
return {
|
|
15
|
+
x1: v.readDoubleBE(0),
|
|
16
|
+
y1: v.readDoubleBE(8),
|
|
17
|
+
x2: v.readDoubleBE(16),
|
|
18
|
+
y2: v.readDoubleBE(24),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
encodeBinary(buf, v) {
|
|
22
|
+
buf.writeDoubleBE(v.x1);
|
|
23
|
+
buf.writeDoubleBE(v.y1);
|
|
24
|
+
buf.writeDoubleBE(v.x2);
|
|
25
|
+
buf.writeDoubleBE(v.y2);
|
|
26
|
+
},
|
|
27
|
+
parseText(v) {
|
|
28
|
+
const m = v.match(BOX_PATTERN1) || v.match(BOX_PATTERN2) || v.match(BOX_PATTERN3);
|
|
29
|
+
if (!m)
|
|
30
|
+
return undefined;
|
|
31
|
+
return {
|
|
32
|
+
x1: parseFloat(m[1]),
|
|
33
|
+
y1: parseFloat(m[2]),
|
|
34
|
+
x2: parseFloat(m[3]),
|
|
35
|
+
y2: parseFloat(m[4]),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
isType(v) {
|
|
39
|
+
return (typeof v === 'object' &&
|
|
40
|
+
Object.keys(v).length === 4 &&
|
|
41
|
+
typeof v.x1 === 'number' &&
|
|
42
|
+
typeof v.y1 === 'number' &&
|
|
43
|
+
typeof v.x2 === 'number' &&
|
|
44
|
+
typeof v.y2 === 'number');
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
exports.ArrayBoxType = {
|
|
48
|
+
...exports.BoxType,
|
|
49
|
+
name: '_box',
|
|
50
|
+
oid: constants_js_1.DataTypeOIDs._box,
|
|
51
|
+
elementsOID: constants_js_1.DataTypeOIDs.box,
|
|
52
|
+
};
|