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