@event-driven-io/dumbo 0.13.0-beta.35 → 0.13.0-beta.36
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/dist/cloudflare.cjs +379 -434
- package/dist/cloudflare.cjs.map +1 -1
- package/dist/cloudflare.d.cts +36 -29
- package/dist/cloudflare.d.ts +36 -29
- package/dist/cloudflare.js +343 -434
- package/dist/cloudflare.js.map +1 -1
- package/dist/core-BeyC5tHn.js +519 -0
- package/dist/core-BeyC5tHn.js.map +1 -0
- package/dist/core-Bf2ujUFy.js +379 -0
- package/dist/core-Bf2ujUFy.js.map +1 -0
- package/dist/core-BgYtAxCm.cjs +3237 -0
- package/dist/core-BgYtAxCm.cjs.map +1 -0
- package/dist/core-DDo4m0Z_.js +2262 -0
- package/dist/core-DDo4m0Z_.js.map +1 -0
- package/dist/core-DmbB4qMn.cjs +656 -0
- package/dist/core-DmbB4qMn.cjs.map +1 -0
- package/dist/core-Go_IA78L.cjs +450 -0
- package/dist/core-Go_IA78L.cjs.map +1 -0
- package/dist/{connectionString-Dch_MIRU.d.cts → index-BDSQvDH2.d.cts} +1010 -922
- package/dist/index-BdWFmDhJ.d.cts +68 -0
- package/dist/index-D1jryNqo.d.ts +198 -0
- package/dist/index-DaP2fTEX.d.ts +67 -0
- package/dist/index-DqVvUav9.d.cts +198 -0
- package/dist/index-S_wp0Eaf.d.cts +67 -0
- package/dist/index-cxtbLiju.d.ts +68 -0
- package/dist/{connectionString-Dch_MIRU.d.ts → index-zkszkJqP.d.ts} +1010 -922
- package/dist/index.cjs +212 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -132
- package/dist/index.d.ts +3 -132
- package/dist/index.js +52 -361
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +366 -431
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +83 -72
- package/dist/pg.d.ts +83 -72
- package/dist/pg.js +320 -431
- package/dist/pg.js.map +1 -1
- package/dist/postgreSQLMetadata-LqX-Z_wo.cjs +118 -0
- package/dist/postgreSQLMetadata-LqX-Z_wo.cjs.map +1 -0
- package/dist/postgreSQLMetadata-zMq8yJo_.js +65 -0
- package/dist/postgreSQLMetadata-zMq8yJo_.js.map +1 -0
- package/dist/postgresql.cjs +25 -50
- package/dist/postgresql.d.cts +3 -61
- package/dist/postgresql.d.ts +3 -61
- package/dist/postgresql.js +4 -50
- package/dist/sqlite.cjs +30 -60
- package/dist/sqlite.d.cts +3 -190
- package/dist/sqlite.d.ts +3 -190
- package/dist/sqlite.js +4 -60
- package/dist/sqlite3.cjs +312 -380
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +79 -77
- package/dist/sqlite3.d.ts +79 -77
- package/dist/sqlite3.js +276 -378
- package/dist/sqlite3.js.map +1 -1
- package/dist/sqliteMetadata-BoQ7Sc9I.js +29 -0
- package/dist/sqliteMetadata-BoQ7Sc9I.js.map +1 -0
- package/dist/sqliteMetadata-D_2pKeCC.cjs +46 -0
- package/dist/sqliteMetadata-D_2pKeCC.cjs.map +1 -0
- package/package.json +12 -12
- package/dist/chunk-33P5766L.js +0 -83
- package/dist/chunk-33P5766L.js.map +0 -1
- package/dist/chunk-4MMMEDQ7.cjs +0 -2944
- package/dist/chunk-4MMMEDQ7.cjs.map +0 -1
- package/dist/chunk-6HAHSSPW.js +0 -701
- package/dist/chunk-6HAHSSPW.js.map +0 -1
- package/dist/chunk-GNH5XC6D.cjs +0 -481
- package/dist/chunk-GNH5XC6D.cjs.map +0 -1
- package/dist/chunk-H2JBS7HM.js +0 -2944
- package/dist/chunk-H2JBS7HM.js.map +0 -1
- package/dist/chunk-JIZGCEPE.cjs +0 -701
- package/dist/chunk-JIZGCEPE.cjs.map +0 -1
- package/dist/chunk-NJI6PJFZ.cjs +0 -83
- package/dist/chunk-NJI6PJFZ.cjs.map +0 -1
- package/dist/chunk-RQ3KKMTP.cjs +0 -34
- package/dist/chunk-RQ3KKMTP.cjs.map +0 -1
- package/dist/chunk-UK7MXVS2.js +0 -34
- package/dist/chunk-UK7MXVS2.js.map +0 -1
- package/dist/chunk-Y5TD53QE.js +0 -481
- package/dist/chunk-Y5TD53QE.js.map +0 -1
- package/dist/columnProcessors-Be2uMYjS.d.cts +0 -8
- package/dist/columnProcessors-D0ivj_SU.d.ts +0 -8
- package/dist/postgresql.cjs.map +0 -1
- package/dist/postgresql.js.map +0 -1
- package/dist/sqlite.cjs.map +0 -1
- package/dist/sqlite.js.map +0 -1
package/dist/pg.cjs
CHANGED
|
@@ -1,467 +1,402 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _chunkGNH5XC6Dcjs = require('./chunk-GNH5XC6D.cjs');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var _chunkNJI6PJFZcjs = require('./chunk-NJI6PJFZ.cjs');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var _chunk4MMMEDQ7cjs = require('./chunk-4MMMEDQ7.cjs');
|
|
38
|
-
|
|
39
|
-
// src/storage/postgresql/pg/connections/connection.ts
|
|
40
|
-
var _pg = require('pg'); var _pg2 = _interopRequireDefault(_pg);
|
|
41
|
-
|
|
42
|
-
// src/storage/postgresql/pg/execute/execute.ts
|
|
43
|
-
|
|
44
|
-
var isPgNativePool = (poolOrClient) => {
|
|
45
|
-
return poolOrClient instanceof _pg2.default.Pool;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_core = require('./core-BgYtAxCm.cjs');
|
|
3
|
+
const require_postgreSQLMetadata = require('./postgreSQLMetadata-LqX-Z_wo.cjs');
|
|
4
|
+
const require_core$1 = require('./core-Go_IA78L.cjs');
|
|
5
|
+
let pg = require("pg");
|
|
6
|
+
pg = require_core.__toESM(pg, 1);
|
|
7
|
+
|
|
8
|
+
//#region src/storage/postgresql/pg/execute/execute.ts
|
|
9
|
+
const isPgNativePool = (poolOrClient) => {
|
|
10
|
+
return poolOrClient instanceof pg.default.Pool;
|
|
46
11
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
12
|
+
const isPgClient = (poolOrClient) => poolOrClient instanceof pg.default.Client;
|
|
13
|
+
const isPgPoolClient = (poolOrClient) => "release" in poolOrClient && typeof poolOrClient.release === "function";
|
|
14
|
+
const pgExecute = async (poolOrClient, handle) => {
|
|
15
|
+
const client = isPgNativePool(poolOrClient) ? await poolOrClient.connect() : poolOrClient;
|
|
16
|
+
try {
|
|
17
|
+
return await handle(client);
|
|
18
|
+
} finally {
|
|
19
|
+
if (isPgNativePool(poolOrClient) && isPgPoolClient(client)) client.release();
|
|
20
|
+
}
|
|
57
21
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return results[0];
|
|
70
|
-
},
|
|
71
|
-
batchQuery: (client, sqls, options) => batchQuery(client, sqls, serializer, options),
|
|
72
|
-
command: async (client, sql, options) => {
|
|
73
|
-
const results = await batchCommand(
|
|
74
|
-
client,
|
|
75
|
-
[sql],
|
|
76
|
-
serializer,
|
|
77
|
-
options
|
|
78
|
-
);
|
|
79
|
-
return results[0];
|
|
80
|
-
},
|
|
81
|
-
batchCommand: (client, sqls, options) => batchCommand(client, sqls, serializer, options),
|
|
82
|
-
formatter: _chunkGNH5XC6Dcjs.pgFormatter
|
|
22
|
+
const pgSQLExecutor = ({ serializer }) => ({
|
|
23
|
+
driverType: PgDriverType,
|
|
24
|
+
query: async (client, sql, options) => {
|
|
25
|
+
return (await batchQuery(client, [sql], serializer, options))[0];
|
|
26
|
+
},
|
|
27
|
+
batchQuery: (client, sqls, options) => batchQuery(client, sqls, serializer, options),
|
|
28
|
+
command: async (client, sql, options) => {
|
|
29
|
+
return (await batchCommand(client, [sql], serializer, options))[0];
|
|
30
|
+
},
|
|
31
|
+
batchCommand: (client, sqls, options) => batchCommand(client, sqls, serializer, options),
|
|
32
|
+
formatter: require_core$1.pgFormatter
|
|
83
33
|
});
|
|
84
34
|
async function batchQuery(client, sqls, serializer, options) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
_chunk4MMMEDQ7cjs.tracer.error("db:sql:batch_query:execute:error", { error });
|
|
111
|
-
throw _chunkGNH5XC6Dcjs.mapPostgresError.call(void 0, error);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return results;
|
|
35
|
+
const results = Array(sqls.length);
|
|
36
|
+
if (options?.timeoutMs) await client.query(`SET statement_timeout = ${options.timeoutMs}`);
|
|
37
|
+
for (let i = 0; i < sqls.length; i++) {
|
|
38
|
+
const { query, params } = require_core$1.pgFormatter.format(sqls[i], { serializer });
|
|
39
|
+
require_core.tracer.info("db:sql:query", {
|
|
40
|
+
query,
|
|
41
|
+
params,
|
|
42
|
+
debugSQL: require_core$1.pgFormatter.describe(sqls[i], { serializer })
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
let result = params.length > 0 ? await client.query(query, params) : await client.query(query);
|
|
46
|
+
if (options?.mapping) result = {
|
|
47
|
+
...result,
|
|
48
|
+
rows: result.rows.map((row) => require_core.mapSQLQueryResult(row, options.mapping))
|
|
49
|
+
};
|
|
50
|
+
results[i] = {
|
|
51
|
+
rowCount: result.rowCount,
|
|
52
|
+
rows: result.rows
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
require_core.tracer.error("db:sql:batch_query:execute:error", { error });
|
|
56
|
+
throw require_core$1.mapPostgresError(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
115
60
|
}
|
|
116
61
|
async function batchCommand(client, sqls, serializer, options) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
} catch (error) {
|
|
145
|
-
_chunk4MMMEDQ7cjs.tracer.error("db:sql:batch_command:execute:error", { error });
|
|
146
|
-
throw _chunkGNH5XC6Dcjs.mapPostgresError.call(void 0, error);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return results;
|
|
62
|
+
const results = Array(sqls.length);
|
|
63
|
+
if (options?.timeoutMs) await client.query(`SET statement_timeout = ${options.timeoutMs}`);
|
|
64
|
+
for (let i = 0; i < sqls.length; i++) {
|
|
65
|
+
const { query, params } = require_core$1.pgFormatter.format(sqls[i], { serializer });
|
|
66
|
+
require_core.tracer.info("db:sql:command", {
|
|
67
|
+
query,
|
|
68
|
+
params,
|
|
69
|
+
debugSQL: require_core$1.pgFormatter.describe(sqls[i], { serializer })
|
|
70
|
+
});
|
|
71
|
+
try {
|
|
72
|
+
let result = params.length > 0 ? await client.query(query, params) : await client.query(query);
|
|
73
|
+
if (options?.mapping) result = {
|
|
74
|
+
...result,
|
|
75
|
+
rows: result.rows.map((row) => require_core.mapSQLQueryResult(row, options.mapping))
|
|
76
|
+
};
|
|
77
|
+
results[i] = {
|
|
78
|
+
rowCount: result.rowCount,
|
|
79
|
+
rows: result.rows
|
|
80
|
+
};
|
|
81
|
+
if (options?.assertChanges && (results[i].rowCount ?? 0) === 0) throw new require_core.BatchCommandNoChangesError(i);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
require_core.tracer.error("db:sql:batch_command:execute:error", { error });
|
|
84
|
+
throw require_core$1.mapPostgresError(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return results;
|
|
150
88
|
}
|
|
151
89
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
},
|
|
183
|
-
execute: _chunk4MMMEDQ7cjs.sqlExecutor.call(void 0, pgSQLExecutor({ serializer }), {
|
|
184
|
-
connect: () => getClient
|
|
185
|
-
}),
|
|
186
|
-
_transactionOptions: _nullishCoalesce(options, () => ( {}))
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/storage/postgresql/pg/connections/transaction.ts
|
|
92
|
+
const pgTransaction = (connection, serializer) => (getClient, options) => ({
|
|
93
|
+
connection: connection(),
|
|
94
|
+
driverType: PgDriverType,
|
|
95
|
+
begin: async () => {
|
|
96
|
+
const client = await getClient;
|
|
97
|
+
const parts = ["BEGIN"];
|
|
98
|
+
if (options?.isolationLevel) parts.push(`ISOLATION LEVEL ${options.isolationLevel}`);
|
|
99
|
+
if (options?.readonly) parts.push("READ ONLY");
|
|
100
|
+
await client.query(parts.join(" "));
|
|
101
|
+
},
|
|
102
|
+
commit: async () => {
|
|
103
|
+
const client = await getClient;
|
|
104
|
+
try {
|
|
105
|
+
await client.query("COMMIT");
|
|
106
|
+
} finally {
|
|
107
|
+
if (options?.close) await options?.close(client);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
rollback: async (error) => {
|
|
111
|
+
const client = await getClient;
|
|
112
|
+
try {
|
|
113
|
+
await client.query("ROLLBACK");
|
|
114
|
+
} finally {
|
|
115
|
+
if (options?.close) await options?.close(client, error);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
execute: require_core.sqlExecutor(pgSQLExecutor({ serializer }), { connect: () => getClient }),
|
|
119
|
+
_transactionOptions: options ?? {}
|
|
187
120
|
});
|
|
188
121
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/storage/postgresql/pg/connections/connection.ts
|
|
124
|
+
const PgDriverType = "PostgreSQL:pg";
|
|
125
|
+
const pgClientConnection = (options) => {
|
|
126
|
+
const { connect, close } = options;
|
|
127
|
+
return require_core.createConnection({
|
|
128
|
+
driverType: PgDriverType,
|
|
129
|
+
connect,
|
|
130
|
+
close,
|
|
131
|
+
initTransaction: (connection) => pgTransaction(connection, options.serializer),
|
|
132
|
+
executor: pgSQLExecutor,
|
|
133
|
+
serializer: options.serializer
|
|
134
|
+
});
|
|
201
135
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
136
|
+
const pgPoolClientConnection = (options) => {
|
|
137
|
+
const { connect, close } = options;
|
|
138
|
+
return require_core.createConnection({
|
|
139
|
+
driverType: PgDriverType,
|
|
140
|
+
connect,
|
|
141
|
+
close,
|
|
142
|
+
initTransaction: (connection) => pgTransaction(connection, options.serializer),
|
|
143
|
+
executor: pgSQLExecutor,
|
|
144
|
+
serializer: options.serializer
|
|
145
|
+
});
|
|
212
146
|
};
|
|
213
147
|
function pgConnection(options) {
|
|
214
|
-
|
|
148
|
+
return options.type === "Client" ? pgClientConnection(options) : pgPoolClientConnection(options);
|
|
215
149
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
await client.end();
|
|
233
|
-
}
|
|
150
|
+
const checkConnection = async (connectionString) => {
|
|
151
|
+
const client = new pg.default.Client({ connectionString });
|
|
152
|
+
try {
|
|
153
|
+
await client.connect();
|
|
154
|
+
return { successful: true };
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
157
|
+
return {
|
|
158
|
+
successful: false,
|
|
159
|
+
errorType: code === "ECONNREFUSED" ? "ConnectionRefused" : code === "28P01" ? "Authentication" : "Unknown",
|
|
160
|
+
code,
|
|
161
|
+
error
|
|
162
|
+
};
|
|
163
|
+
} finally {
|
|
164
|
+
await client.end();
|
|
165
|
+
}
|
|
234
166
|
};
|
|
235
167
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
client.setTypeParser(3802, (val) => options.serializer.deserialize(val));
|
|
245
|
-
client.setTypeParser(114, (val) => options.serializer.deserialize(val));
|
|
246
|
-
}
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/storage/postgresql/pg/serialization/index.ts
|
|
170
|
+
const setPgTypeParser = (client, options) => {
|
|
171
|
+
if (options?.parseBigInts === true) client.setTypeParser(20, (val) => BigInt(val));
|
|
172
|
+
if (options?.serializer) {
|
|
173
|
+
client.setTypeParser(3802, (val) => options.serializer.deserialize(val));
|
|
174
|
+
client.setTypeParser(114, (val) => options.serializer.deserialize(val));
|
|
175
|
+
}
|
|
247
176
|
};
|
|
248
177
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/storage/postgresql/pg/connections/pool.ts
|
|
180
|
+
const pgNativePool = (options) => {
|
|
181
|
+
const { connectionString, database } = options;
|
|
182
|
+
const pool = getPgPool({
|
|
183
|
+
connectionString,
|
|
184
|
+
database
|
|
185
|
+
});
|
|
186
|
+
const getConnection = () => pgConnection({
|
|
187
|
+
type: "PoolClient",
|
|
188
|
+
connect: async () => {
|
|
189
|
+
const client = await pool.connect();
|
|
190
|
+
setPgTypeParser(client, {
|
|
191
|
+
parseBigInts: true,
|
|
192
|
+
serializer: options.serializer
|
|
193
|
+
});
|
|
194
|
+
return client;
|
|
195
|
+
},
|
|
196
|
+
close: (client) => Promise.resolve(client.release()),
|
|
197
|
+
serializer: options.serializer
|
|
198
|
+
});
|
|
199
|
+
const open = () => Promise.resolve(getConnection());
|
|
200
|
+
const close = () => endPgPool({
|
|
201
|
+
connectionString,
|
|
202
|
+
database
|
|
203
|
+
});
|
|
204
|
+
return require_core.createConnectionPool({
|
|
205
|
+
driverType: PgDriverType,
|
|
206
|
+
connection: open,
|
|
207
|
+
close,
|
|
208
|
+
getConnection
|
|
209
|
+
});
|
|
274
210
|
};
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
211
|
+
const pgAmbientNativePool = (options) => {
|
|
212
|
+
const { pool } = options;
|
|
213
|
+
return require_core.createConnectionPool({
|
|
214
|
+
driverType: PgDriverType,
|
|
215
|
+
getConnection: () => pgConnection({
|
|
216
|
+
type: "PoolClient",
|
|
217
|
+
connect: () => pool.connect(),
|
|
218
|
+
close: (client) => Promise.resolve(client.release()),
|
|
219
|
+
serializer: options.serializer
|
|
220
|
+
})
|
|
221
|
+
});
|
|
286
222
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
223
|
+
const pgAmbientConnectionPool = (options) => {
|
|
224
|
+
const { connection } = options;
|
|
225
|
+
return require_core.createAmbientConnectionPool({
|
|
226
|
+
driverType: PgDriverType,
|
|
227
|
+
connection
|
|
228
|
+
});
|
|
293
229
|
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
230
|
+
const pgClientPool = (options) => {
|
|
231
|
+
const { connectionString, database } = options;
|
|
232
|
+
return require_core.createConnectionPool({
|
|
233
|
+
driverType: PgDriverType,
|
|
234
|
+
getConnection: () => {
|
|
235
|
+
const connect = async () => {
|
|
236
|
+
const client = new pg.default.Client({
|
|
237
|
+
connectionString,
|
|
238
|
+
database
|
|
239
|
+
});
|
|
240
|
+
setPgTypeParser(client, {
|
|
241
|
+
parseBigInts: true,
|
|
242
|
+
serializer: options.serializer
|
|
243
|
+
});
|
|
244
|
+
await client.connect();
|
|
245
|
+
return client;
|
|
246
|
+
};
|
|
247
|
+
return pgConnection({
|
|
248
|
+
type: "Client",
|
|
249
|
+
connect,
|
|
250
|
+
close: (client) => client.end(),
|
|
251
|
+
serializer: options.serializer
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
});
|
|
316
255
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
256
|
+
const pgAmbientClientPool = (options) => {
|
|
257
|
+
const { client } = options;
|
|
258
|
+
const getConnection = () => {
|
|
259
|
+
const connect = () => Promise.resolve(client);
|
|
260
|
+
return pgConnection({
|
|
261
|
+
type: "Client",
|
|
262
|
+
connect,
|
|
263
|
+
close: () => Promise.resolve(),
|
|
264
|
+
serializer: options.serializer
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
const open = () => Promise.resolve(getConnection());
|
|
268
|
+
const close = () => Promise.resolve();
|
|
269
|
+
return require_core.createConnectionPool({
|
|
270
|
+
driverType: PgDriverType,
|
|
271
|
+
connection: open,
|
|
272
|
+
close,
|
|
273
|
+
getConnection
|
|
274
|
+
});
|
|
336
275
|
};
|
|
337
276
|
function pgPool(options) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
277
|
+
const { connectionString, database } = options;
|
|
278
|
+
const serializer = options.serialization?.serializer ?? require_core.JSONSerializer;
|
|
279
|
+
if ("client" in options && options.client) return pgAmbientClientPool({
|
|
280
|
+
client: options.client,
|
|
281
|
+
serializer
|
|
282
|
+
});
|
|
283
|
+
if ("connection" in options && options.connection) return pgAmbientConnectionPool({ connection: options.connection });
|
|
284
|
+
if ("pooled" in options && options.pooled === false) return pgClientPool({
|
|
285
|
+
connectionString,
|
|
286
|
+
database,
|
|
287
|
+
serializer
|
|
288
|
+
});
|
|
289
|
+
if ("pool" in options && options.pool) return pgAmbientNativePool({
|
|
290
|
+
pool: options.pool,
|
|
291
|
+
serializer
|
|
292
|
+
});
|
|
293
|
+
return pgNativePool({
|
|
294
|
+
connectionString,
|
|
295
|
+
database,
|
|
296
|
+
serializer
|
|
297
|
+
});
|
|
355
298
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return _nullishCoalesce(pools.get(lookupKey), () => ( pools.set(lookupKey, new _pg2.default.Pool(poolOptions)).get(lookupKey)));
|
|
299
|
+
const pools = /* @__PURE__ */ new Map();
|
|
300
|
+
const usageCounter = /* @__PURE__ */ new Map();
|
|
301
|
+
const getPgPool = (connectionStringOrOptions) => {
|
|
302
|
+
const connectionString = typeof connectionStringOrOptions === "string" ? connectionStringOrOptions : connectionStringOrOptions.connectionString;
|
|
303
|
+
const poolOptions = typeof connectionStringOrOptions === "string" ? { connectionString } : connectionStringOrOptions;
|
|
304
|
+
const lookupKey = key(connectionString, poolOptions.database ?? (poolOptions.connectionString ? require_postgreSQLMetadata.parseDatabaseName(poolOptions.connectionString) ?? "postgres" : void 0));
|
|
305
|
+
updatePoolUsageCounter(lookupKey, 1);
|
|
306
|
+
return pools.get(lookupKey) ?? pools.set(lookupKey, new pg.default.Pool(poolOptions)).get(lookupKey);
|
|
365
307
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
database = _nullishCoalesce(_nullishCoalesce(database, () => ( _chunkNJI6PJFZcjs.parseDatabaseName.call(void 0, connectionString))), () => ( void 0));
|
|
372
|
-
const lookupKey = key(connectionString, database);
|
|
373
|
-
const pool = pools.get(lookupKey);
|
|
374
|
-
if (pool && (updatePoolUsageCounter(lookupKey, -1) <= 0 || force === true)) {
|
|
375
|
-
await onEndPool(lookupKey, pool);
|
|
376
|
-
}
|
|
308
|
+
const endPgPool = async ({ connectionString, database, force }) => {
|
|
309
|
+
database = database ?? require_postgreSQLMetadata.parseDatabaseName(connectionString) ?? void 0;
|
|
310
|
+
const lookupKey = key(connectionString, database);
|
|
311
|
+
const pool = pools.get(lookupKey);
|
|
312
|
+
if (pool && (updatePoolUsageCounter(lookupKey, -1) <= 0 || force === true)) await onEndPool(lookupKey, pool);
|
|
377
313
|
};
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
314
|
+
const onEndPool = async (lookupKey, pool) => {
|
|
315
|
+
try {
|
|
316
|
+
await pool.end();
|
|
317
|
+
} catch (error) {
|
|
318
|
+
require_core.tracer.error("connection-closing-error", {
|
|
319
|
+
lookupKey,
|
|
320
|
+
error
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
pools.delete(lookupKey);
|
|
385
324
|
};
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
usageCounter.set(lookupKey, currentCounter + by);
|
|
394
|
-
return newCounter;
|
|
325
|
+
const endAllPgPools = () => Promise.all([...pools.entries()].map(([lookupKey, pool]) => onEndPool(lookupKey, pool)));
|
|
326
|
+
const key = (connectionString, database) => `${connectionString}|${database ?? "postgres"}`;
|
|
327
|
+
const updatePoolUsageCounter = (lookupKey, by) => {
|
|
328
|
+
const currentCounter = usageCounter.get(lookupKey) ?? 0;
|
|
329
|
+
const newCounter = currentCounter + by;
|
|
330
|
+
usageCounter.set(lookupKey, currentCounter + by);
|
|
331
|
+
return newCounter;
|
|
395
332
|
};
|
|
396
333
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/storage/postgresql/pg/index.ts
|
|
336
|
+
const tryParseConnectionString = (connectionString) => {
|
|
337
|
+
try {
|
|
338
|
+
return require_postgreSQLMetadata.PostgreSQLConnectionString(connectionString);
|
|
339
|
+
} catch {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
404
342
|
};
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
tryParseConnectionString
|
|
413
|
-
),
|
|
414
|
-
databaseMetadata: _chunkNJI6PJFZcjs.postgreSQLMetadata
|
|
343
|
+
const pgDumboDriver = {
|
|
344
|
+
driverType: PgDriverType,
|
|
345
|
+
createPool: (options) => pgPool(options),
|
|
346
|
+
sqlFormatter: require_core$1.pgFormatter,
|
|
347
|
+
defaultMigratorOptions: require_core$1.DefaultPostgreSQLMigratorOptions,
|
|
348
|
+
canHandle: require_core.canHandleDriverWithConnectionString(PgDriverType, tryParseConnectionString),
|
|
349
|
+
databaseMetadata: require_postgreSQLMetadata.postgreSQLMetadata
|
|
415
350
|
};
|
|
416
|
-
|
|
417
|
-
|
|
351
|
+
const usePgDumboDriver = () => {
|
|
352
|
+
require_core.dumboDatabaseDriverRegistry.register(PgDriverType, pgDumboDriver);
|
|
418
353
|
};
|
|
419
354
|
usePgDumboDriver();
|
|
420
355
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
exports.
|
|
356
|
+
//#endregion
|
|
357
|
+
exports.AdvisoryLock = require_core$1.AdvisoryLock;
|
|
358
|
+
exports.DefaultPostgreSQLMigratorOptions = require_core$1.DefaultPostgreSQLMigratorOptions;
|
|
359
|
+
exports.PgDriverType = PgDriverType;
|
|
360
|
+
exports.PostgreSQLArrayProcessor = require_core$1.PostgreSQLArrayProcessor;
|
|
361
|
+
exports.PostgreSQLConnectionString = require_postgreSQLMetadata.PostgreSQLConnectionString;
|
|
362
|
+
exports.PostgreSQLDatabaseName = require_core$1.PostgreSQLDatabaseName;
|
|
363
|
+
exports.PostgreSQLExpandSQLInProcessor = require_core$1.PostgreSQLExpandSQLInProcessor;
|
|
364
|
+
exports.acquireAdvisoryLock = require_core$1.acquireAdvisoryLock;
|
|
365
|
+
exports.advisoryLock = require_core$1.advisoryLock;
|
|
366
|
+
exports.checkConnection = checkConnection;
|
|
367
|
+
exports.defaultPostgreSQLConnectionString = require_postgreSQLMetadata.defaultPostgreSQLConnectionString;
|
|
368
|
+
exports.defaultPostgreSqlDatabase = require_postgreSQLMetadata.defaultPostgreSqlDatabase;
|
|
369
|
+
exports.endAllPgPools = endAllPgPools;
|
|
370
|
+
exports.endPgPool = endPgPool;
|
|
371
|
+
exports.functionExists = require_postgreSQLMetadata.functionExists;
|
|
372
|
+
exports.functionExistsSQL = require_postgreSQLMetadata.functionExistsSQL;
|
|
373
|
+
exports.getPgPool = getPgPool;
|
|
374
|
+
exports.isPgClient = isPgClient;
|
|
375
|
+
exports.isPgNativePool = isPgNativePool;
|
|
376
|
+
exports.isPgPoolClient = isPgPoolClient;
|
|
377
|
+
exports.mapPostgresError = require_core$1.mapPostgresError;
|
|
378
|
+
exports.onEndPool = onEndPool;
|
|
379
|
+
exports.parseDatabaseName = require_postgreSQLMetadata.parseDatabaseName;
|
|
380
|
+
exports.pgAmbientClientPool = pgAmbientClientPool;
|
|
381
|
+
exports.pgAmbientConnectionPool = pgAmbientConnectionPool;
|
|
382
|
+
exports.pgAmbientNativePool = pgAmbientNativePool;
|
|
383
|
+
exports.pgClientConnection = pgClientConnection;
|
|
384
|
+
exports.pgClientPool = pgClientPool;
|
|
385
|
+
exports.pgConnection = pgConnection;
|
|
386
|
+
exports.pgDumboDriver = pgDumboDriver;
|
|
387
|
+
exports.pgExecute = pgExecute;
|
|
388
|
+
exports.pgFormatter = require_core$1.pgFormatter;
|
|
389
|
+
exports.pgNativePool = pgNativePool;
|
|
390
|
+
exports.pgPool = pgPool;
|
|
391
|
+
exports.pgPoolClientConnection = pgPoolClientConnection;
|
|
392
|
+
exports.pgSQLExecutor = pgSQLExecutor;
|
|
393
|
+
exports.pgTransaction = pgTransaction;
|
|
394
|
+
exports.postgreSQLColumnProcessors = require_core$1.postgreSQLColumnProcessors;
|
|
395
|
+
exports.postgreSQLMetadata = require_postgreSQLMetadata.postgreSQLMetadata;
|
|
396
|
+
exports.releaseAdvisoryLock = require_core$1.releaseAdvisoryLock;
|
|
397
|
+
exports.setPgTypeParser = setPgTypeParser;
|
|
398
|
+
exports.tableExists = require_postgreSQLMetadata.tableExists;
|
|
399
|
+
exports.tableExistsSQL = require_postgreSQLMetadata.tableExistsSQL;
|
|
400
|
+
exports.tryAcquireAdvisoryLock = require_core$1.tryAcquireAdvisoryLock;
|
|
401
|
+
exports.usePgDumboDriver = usePgDumboDriver;
|
|
467
402
|
//# sourceMappingURL=pg.cjs.map
|