@take-out/postgres 0.0.28
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/LICENSE +21 -0
- package/README.md +242 -0
- package/cli.cjs +3 -0
- package/dist/cjs/build.cjs +26 -0
- package/dist/cjs/build.js +21 -0
- package/dist/cjs/build.js.map +6 -0
- package/dist/cjs/build.native.js +29 -0
- package/dist/cjs/build.native.js.map +1 -0
- package/dist/cjs/cli.cjs +156 -0
- package/dist/cjs/cli.js +128 -0
- package/dist/cjs/cli.js.map +6 -0
- package/dist/cjs/cli.native.js +164 -0
- package/dist/cjs/cli.native.js.map +1 -0
- package/dist/cjs/createServerHelpers.cjs +37 -0
- package/dist/cjs/createServerHelpers.js +28 -0
- package/dist/cjs/createServerHelpers.js.map +6 -0
- package/dist/cjs/createServerHelpers.native.js +43 -0
- package/dist/cjs/createServerHelpers.native.js.map +1 -0
- package/dist/cjs/helpers/chunkedQuery.cjs +60 -0
- package/dist/cjs/helpers/chunkedQuery.js +51 -0
- package/dist/cjs/helpers/chunkedQuery.js.map +6 -0
- package/dist/cjs/helpers/chunkedQuery.native.js +73 -0
- package/dist/cjs/helpers/chunkedQuery.native.js.map +1 -0
- package/dist/cjs/helpers/getDBClient.cjs +172 -0
- package/dist/cjs/helpers/getDBClient.js +179 -0
- package/dist/cjs/helpers/getDBClient.js.map +6 -0
- package/dist/cjs/helpers/getDBClient.native.js +189 -0
- package/dist/cjs/helpers/getDBClient.native.js.map +1 -0
- package/dist/cjs/index.cjs +59 -0
- package/dist/cjs/index.js +45 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/index.native.js +64 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/migrate.cjs +117 -0
- package/dist/cjs/migrate.js +106 -0
- package/dist/cjs/migrate.js.map +6 -0
- package/dist/cjs/migrate.native.js +185 -0
- package/dist/cjs/migrate.native.js.map +1 -0
- package/dist/cjs/scripts/build-migrations.cjs +81 -0
- package/dist/cjs/scripts/build-migrations.js +69 -0
- package/dist/cjs/scripts/build-migrations.js.map +6 -0
- package/dist/cjs/scripts/build-migrations.native.js +86 -0
- package/dist/cjs/scripts/build-migrations.native.js.map +1 -0
- package/dist/cjs/scripts/drizzle-migrations-sync.cjs +111 -0
- package/dist/cjs/scripts/drizzle-migrations-sync.js +101 -0
- package/dist/cjs/scripts/drizzle-migrations-sync.js.map +6 -0
- package/dist/cjs/scripts/drizzle-migrations-sync.native.js +209 -0
- package/dist/cjs/scripts/drizzle-migrations-sync.native.js.map +1 -0
- package/dist/cjs/scripts/migration-add.cjs +53 -0
- package/dist/cjs/scripts/migration-add.js +40 -0
- package/dist/cjs/scripts/migration-add.js.map +6 -0
- package/dist/cjs/scripts/migration-add.native.js +72 -0
- package/dist/cjs/scripts/migration-add.native.js.map +1 -0
- package/dist/cjs/scripts/pg_dump.cjs +49 -0
- package/dist/cjs/scripts/pg_dump.js +36 -0
- package/dist/cjs/scripts/pg_dump.js.map +6 -0
- package/dist/cjs/scripts/pg_dump.native.js +55 -0
- package/dist/cjs/scripts/pg_dump.native.js.map +1 -0
- package/dist/cjs/scripts/psql.cjs +50 -0
- package/dist/cjs/scripts/psql.js +37 -0
- package/dist/cjs/scripts/psql.js.map +6 -0
- package/dist/cjs/scripts/psql.native.js +56 -0
- package/dist/cjs/scripts/psql.native.js.map +1 -0
- package/dist/cjs/sql.cjs +40 -0
- package/dist/cjs/sql.js +35 -0
- package/dist/cjs/sql.js.map +6 -0
- package/dist/cjs/sql.native.js +49 -0
- package/dist/cjs/sql.native.js.map +1 -0
- package/dist/esm/build.js +5 -0
- package/dist/esm/build.js.map +6 -0
- package/dist/esm/build.mjs +3 -0
- package/dist/esm/build.mjs.map +1 -0
- package/dist/esm/build.native.js +3 -0
- package/dist/esm/build.native.js.map +1 -0
- package/dist/esm/cli.js +134 -0
- package/dist/esm/cli.js.map +6 -0
- package/dist/esm/cli.mjs +157 -0
- package/dist/esm/cli.mjs.map +1 -0
- package/dist/esm/cli.native.js +162 -0
- package/dist/esm/cli.native.js.map +1 -0
- package/dist/esm/createServerHelpers.js +13 -0
- package/dist/esm/createServerHelpers.js.map +6 -0
- package/dist/esm/createServerHelpers.mjs +14 -0
- package/dist/esm/createServerHelpers.mjs.map +1 -0
- package/dist/esm/createServerHelpers.native.js +17 -0
- package/dist/esm/createServerHelpers.native.js.map +1 -0
- package/dist/esm/helpers/chunkedQuery.js +35 -0
- package/dist/esm/helpers/chunkedQuery.js.map +6 -0
- package/dist/esm/helpers/chunkedQuery.mjs +36 -0
- package/dist/esm/helpers/chunkedQuery.mjs.map +1 -0
- package/dist/esm/helpers/chunkedQuery.native.js +46 -0
- package/dist/esm/helpers/chunkedQuery.native.js.map +1 -0
- package/dist/esm/helpers/getDBClient.js +155 -0
- package/dist/esm/helpers/getDBClient.js.map +6 -0
- package/dist/esm/helpers/getDBClient.mjs +136 -0
- package/dist/esm/helpers/getDBClient.mjs.map +1 -0
- package/dist/esm/helpers/getDBClient.native.js +150 -0
- package/dist/esm/helpers/getDBClient.native.js.map +1 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +18 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +20 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/migrate.js +91 -0
- package/dist/esm/migrate.js.map +6 -0
- package/dist/esm/migrate.mjs +94 -0
- package/dist/esm/migrate.mjs.map +1 -0
- package/dist/esm/migrate.native.js +159 -0
- package/dist/esm/migrate.native.js.map +1 -0
- package/dist/esm/scripts/build-migrations.js +46 -0
- package/dist/esm/scripts/build-migrations.js.map +6 -0
- package/dist/esm/scripts/build-migrations.mjs +47 -0
- package/dist/esm/scripts/build-migrations.mjs.map +1 -0
- package/dist/esm/scripts/build-migrations.native.js +49 -0
- package/dist/esm/scripts/build-migrations.native.js.map +1 -0
- package/dist/esm/scripts/drizzle-migrations-sync.js +87 -0
- package/dist/esm/scripts/drizzle-migrations-sync.js.map +6 -0
- package/dist/esm/scripts/drizzle-migrations-sync.mjs +88 -0
- package/dist/esm/scripts/drizzle-migrations-sync.mjs.map +1 -0
- package/dist/esm/scripts/drizzle-migrations-sync.native.js +183 -0
- package/dist/esm/scripts/drizzle-migrations-sync.native.js.map +1 -0
- package/dist/esm/scripts/migration-add.js +25 -0
- package/dist/esm/scripts/migration-add.js.map +6 -0
- package/dist/esm/scripts/migration-add.mjs +30 -0
- package/dist/esm/scripts/migration-add.mjs.map +1 -0
- package/dist/esm/scripts/migration-add.native.js +46 -0
- package/dist/esm/scripts/migration-add.native.js.map +1 -0
- package/dist/esm/scripts/pg_dump.js +20 -0
- package/dist/esm/scripts/pg_dump.js.map +6 -0
- package/dist/esm/scripts/pg_dump.mjs +26 -0
- package/dist/esm/scripts/pg_dump.mjs.map +1 -0
- package/dist/esm/scripts/pg_dump.native.js +29 -0
- package/dist/esm/scripts/pg_dump.native.js.map +1 -0
- package/dist/esm/scripts/psql.js +21 -0
- package/dist/esm/scripts/psql.js.map +6 -0
- package/dist/esm/scripts/psql.mjs +27 -0
- package/dist/esm/scripts/psql.mjs.map +1 -0
- package/dist/esm/scripts/psql.native.js +30 -0
- package/dist/esm/scripts/psql.native.js.map +1 -0
- package/dist/esm/sql.js +19 -0
- package/dist/esm/sql.js.map +6 -0
- package/dist/esm/sql.mjs +15 -0
- package/dist/esm/sql.mjs.map +1 -0
- package/dist/esm/sql.native.js +21 -0
- package/dist/esm/sql.native.js.map +1 -0
- package/package.json +67 -0
- package/src/build.ts +2 -0
- package/src/cli.ts +153 -0
- package/src/createServerHelpers.ts +20 -0
- package/src/helpers/chunkedQuery.ts +91 -0
- package/src/helpers/getDBClient.ts +264 -0
- package/src/index.ts +36 -0
- package/src/migrate.ts +192 -0
- package/src/scripts/build-migrations.ts +66 -0
- package/src/scripts/drizzle-migrations-sync.ts +179 -0
- package/src/scripts/migration-add.ts +54 -0
- package/src/scripts/pg_dump.ts +46 -0
- package/src/scripts/psql.ts +51 -0
- package/src/sql.ts +36 -0
- package/types/build.d.ts +2 -0
- package/types/build.d.ts.map +1 -0
- package/types/cli.d.ts +3 -0
- package/types/cli.d.ts.map +1 -0
- package/types/createServerHelpers.d.ts +9 -0
- package/types/createServerHelpers.d.ts.map +1 -0
- package/types/helpers/chunkedQuery.d.ts +17 -0
- package/types/helpers/chunkedQuery.d.ts.map +1 -0
- package/types/helpers/getDBClient.d.ts +11 -0
- package/types/helpers/getDBClient.d.ts.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/index.d.ts.map +1 -0
- package/types/migrate.d.ts +25 -0
- package/types/migrate.d.ts.map +1 -0
- package/types/scripts/build-migrations.d.ts +8 -0
- package/types/scripts/build-migrations.d.ts.map +1 -0
- package/types/scripts/drizzle-migrations-sync.d.ts +11 -0
- package/types/scripts/drizzle-migrations-sync.d.ts.map +1 -0
- package/types/scripts/migration-add.d.ts +6 -0
- package/types/scripts/migration-add.d.ts.map +1 -0
- package/types/scripts/pg_dump.d.ts +11 -0
- package/types/scripts/pg_dump.d.ts.map +1 -0
- package/types/scripts/psql.d.ts +11 -0
- package/types/scripts/psql.d.ts.map +1 -0
- package/types/sql.d.ts +9 -0
- package/types/sql.d.ts.map +1 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var getDBClient_exports = {};
|
|
24
|
+
__export(getDBClient_exports, {
|
|
25
|
+
getDBClient: () => getDBClient,
|
|
26
|
+
getNewClient: () => getNewClient,
|
|
27
|
+
queryDb: () => queryDb
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(getDBClient_exports);
|
|
30
|
+
var import_pg = __toESM(require("pg"), 1);
|
|
31
|
+
const cache = /* @__PURE__ */ new Map(), createPoolKey = (connectionString) => connectionString, getOrCreatePoolCache = (connectionString, config) => {
|
|
32
|
+
const key = createPoolKey(connectionString);
|
|
33
|
+
return cache.has(key) || cache.set(key, {
|
|
34
|
+
pool: new import_pg.default.Pool(config),
|
|
35
|
+
maxConnections: null,
|
|
36
|
+
reservedConnections: null,
|
|
37
|
+
openedConnections: null,
|
|
38
|
+
openedConnectionsLastUpdate: null
|
|
39
|
+
}), cache.get(key);
|
|
40
|
+
};
|
|
41
|
+
async function getDBClient(options = {}) {
|
|
42
|
+
const { pool, connectionString, retries = 8 } = options;
|
|
43
|
+
if (!pool && !connectionString)
|
|
44
|
+
throw new Error("Either pool or connectionString must be provided");
|
|
45
|
+
let client = null;
|
|
46
|
+
try {
|
|
47
|
+
return client = await tryToGetNewClientFromPool(pool, connectionString, retries), client;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw console.error("Failed to get DB client:", error), error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function tryToGetNewClientFromPool(providedPool, connectionString, retries) {
|
|
53
|
+
const { default: retry } = await import("async-retry");
|
|
54
|
+
return await retry(
|
|
55
|
+
async () => {
|
|
56
|
+
if (providedPool) {
|
|
57
|
+
console.info("Connecting to provided pool...");
|
|
58
|
+
const client2 = await providedPool.connect();
|
|
59
|
+
return console.info("Connected to pool"), client2;
|
|
60
|
+
}
|
|
61
|
+
if (!connectionString)
|
|
62
|
+
throw new Error("No connection string provided");
|
|
63
|
+
const poolCache = getOrCreatePoolCache(connectionString, {
|
|
64
|
+
connectionString,
|
|
65
|
+
connectionTimeoutMillis: 5e3,
|
|
66
|
+
// idle_session_timeout set to 35s on server, client timeout at 30s
|
|
67
|
+
// fix via https://github.com/brianc/node-postgres/issues/2718#issuecomment-2094885323
|
|
68
|
+
idleTimeoutMillis: 3e4,
|
|
69
|
+
allowExitOnIdle: !0
|
|
70
|
+
});
|
|
71
|
+
console.info(`Connecting to pool ${connectionString}...`);
|
|
72
|
+
const client = await poolCache.pool.connect();
|
|
73
|
+
return console.info("Connected to pool"), client;
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
retries,
|
|
77
|
+
minTimeout: 300,
|
|
78
|
+
factor: 2,
|
|
79
|
+
maxTimeout: 8e3
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
async function queryDb(queryText, params, options = {}) {
|
|
84
|
+
let client = null;
|
|
85
|
+
try {
|
|
86
|
+
return client = await tryToGetNewClientFromPool(
|
|
87
|
+
options.pool,
|
|
88
|
+
options.connectionString,
|
|
89
|
+
options.retries || 8
|
|
90
|
+
), await client.query(queryText, params);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw console.error("Database query failed:", {
|
|
93
|
+
query: queryText,
|
|
94
|
+
error: error instanceof Error ? error.message : String(error)
|
|
95
|
+
}), error;
|
|
96
|
+
} finally {
|
|
97
|
+
if (client && options.connectionString)
|
|
98
|
+
if (await checkForTooManyConnections(
|
|
99
|
+
client,
|
|
100
|
+
options.connectionString
|
|
101
|
+
)) {
|
|
102
|
+
const poolCache = cache.get(createPoolKey(options.connectionString));
|
|
103
|
+
client.release(), await poolCache?.pool.end(), poolCache && cache.delete(createPoolKey(options.connectionString));
|
|
104
|
+
} else
|
|
105
|
+
client.release();
|
|
106
|
+
else client && client.release();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function checkForTooManyConnections(client, connectionString) {
|
|
110
|
+
const poolCache = cache.get(createPoolKey(connectionString));
|
|
111
|
+
if (!poolCache) return !1;
|
|
112
|
+
const currentTime = Date.now(), openedConnectionsMaxAge = 1e4, maxConnectionsTolerance = 0.9;
|
|
113
|
+
if (poolCache.maxConnections === null || poolCache.reservedConnections === null) {
|
|
114
|
+
const [maxConnections, reservedConnections] = await getConnectionLimits(client);
|
|
115
|
+
console.info(
|
|
116
|
+
`Max connections: ${maxConnections}, Reserved connections: ${reservedConnections}`
|
|
117
|
+
), poolCache.maxConnections = maxConnections, poolCache.reservedConnections = reservedConnections;
|
|
118
|
+
}
|
|
119
|
+
if (poolCache.openedConnections === null || poolCache.openedConnectionsLastUpdate === null || currentTime - poolCache.openedConnectionsLastUpdate > openedConnectionsMaxAge) {
|
|
120
|
+
const openedConnections = await getOpenedConnections(client, connectionString);
|
|
121
|
+
poolCache.openedConnections = openedConnections, poolCache.openedConnectionsLastUpdate = currentTime;
|
|
122
|
+
}
|
|
123
|
+
return poolCache.openedConnections > (poolCache.maxConnections - poolCache.reservedConnections) * maxConnectionsTolerance ? (console.warn(
|
|
124
|
+
`Too many connections detected: ${poolCache.openedConnections}/${poolCache.maxConnections - poolCache.reservedConnections}`
|
|
125
|
+
), !0) : !1;
|
|
126
|
+
}
|
|
127
|
+
async function getConnectionLimits(client) {
|
|
128
|
+
console.info("Getting connection limits...");
|
|
129
|
+
const maxConnectionsResult = await client.query("SHOW max_connections"), reservedConnectionResult = await client.query(
|
|
130
|
+
"SHOW superuser_reserved_connections"
|
|
131
|
+
);
|
|
132
|
+
return [
|
|
133
|
+
Number.parseInt(maxConnectionsResult.rows[0].max_connections, 10),
|
|
134
|
+
Number.parseInt(reservedConnectionResult.rows[0].superuser_reserved_connections, 10)
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
async function getOpenedConnections(client, connectionString) {
|
|
138
|
+
const dbName = new URL(connectionString).pathname.slice(1);
|
|
139
|
+
console.info("Getting opened connections...");
|
|
140
|
+
const openConnectionsResult = await client.query(
|
|
141
|
+
"SELECT numbackends as opened_connections FROM pg_stat_database WHERE datname = $1",
|
|
142
|
+
[dbName]
|
|
143
|
+
), result = Number.parseInt(
|
|
144
|
+
openConnectionsResult.rows[0]?.opened_connections || 0,
|
|
145
|
+
10
|
|
146
|
+
);
|
|
147
|
+
return console.info(`Opened connections: ${result}`), result;
|
|
148
|
+
}
|
|
149
|
+
async function getNewClient(options = {}) {
|
|
150
|
+
const { connectionString } = options;
|
|
151
|
+
if (!connectionString)
|
|
152
|
+
throw new Error("connectionString is required for getNewClient");
|
|
153
|
+
try {
|
|
154
|
+
return await tryToGetNewClient(connectionString);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw console.error("Failed to get new client:", error), error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function tryToGetNewClient(connectionString) {
|
|
160
|
+
const configurations = {
|
|
161
|
+
connectionString,
|
|
162
|
+
connectionTimeoutMillis: 5e3,
|
|
163
|
+
idleTimeoutMillis: 3e4,
|
|
164
|
+
allowExitOnIdle: !0
|
|
165
|
+
}, { default: retry } = await import("async-retry");
|
|
166
|
+
return await retry(
|
|
167
|
+
async () => {
|
|
168
|
+
const newClient = new import_pg.default.Client(configurations);
|
|
169
|
+
return await newClient.connect(), newClient;
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
retries: 10,
|
|
173
|
+
minTimeout: 100,
|
|
174
|
+
factor: 2,
|
|
175
|
+
maxTimeout: 5e3
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=getDBClient.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/getDBClient.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA+C;AAY/C,MAAM,QAAQ,oBAAI,IAShB,GAEI,gBAAgB,CAAC,qBAA6B,kBAE9C,uBAAuB,CAAC,kBAA0B,WAA0B;AAChF,QAAM,MAAM,cAAc,gBAAgB;AAE1C,SAAK,MAAM,IAAI,GAAG,KAChB,MAAM,IAAI,KAAK;AAAA,IACb,MAAM,IAAI,UAAAA,QAAG,KAAK,MAAM;AAAA,IACxB,gBAAgB;AAAA,IAChB,qBAAqB;AAAA,IACrB,mBAAmB;AAAA,IACnB,6BAA6B;AAAA,EAC/B,CAAC,GAGI,MAAM,IAAI,GAAG;AACtB;AAEA,eAAsB,YAAY,UAA8B,CAAC,GAAwB;AACvF,QAAM,EAAE,MAAM,kBAAkB,UAAU,EAAE,IAAI;AAEhD,MAAI,CAAC,QAAQ,CAAC;AACZ,UAAM,IAAI,MAAM,kDAAkD;AAGpE,MAAI,SAA4B;AAEhC,MAAI;AACF,oBAAS,MAAM,0BAA0B,MAAM,kBAAkB,OAAO,GACjE;AAAA,EACT,SAAS,OAAO;AACd,kBAAQ,MAAM,4BAA4B,KAAK,GACzC;AAAA,EACR;AACF;AAEA,eAAe,0BACb,cACA,kBACA,SACqB;AACrB,QAAM,EAAE,SAAS,MAAM,IAAI,MAAM,OAAO,aAAa;AAsCrD,SArCuB,MAAM;AAAA,IAC3B,YAAY;AACV,UAAI,cAAc;AAChB,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,MAAM,OAAO;AAAA,IACzC;AAAA,IACA,CAAC,MAAM;AAAA,EACT,GACM,SAAS,OAAO;AAAA,IACpB,sBAAsB,KAAK,CAAC,GAAG,sBAAsB;AAAA,IACrD;AAAA,EACF;AACA,iBAAQ,KAAK,uBAAuB,MAAM,EAAE,GACrC;AACT;AAEA,eAAsB,aAAa,UAA8B,CAAC,GAAuB;AACvF,QAAM,EAAE,iBAAiB,IAAI;AAE7B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,+CAA+C;AAGjE,MAAI;AAEF,WADe,MAAM,kBAAkB,gBAAgB;AAAA,EAEzD,SAAS,OAAO;AACd,kBAAQ,MAAM,6BAA6B,KAAK,GAC1C;AAAA,EACR;AACF;AAEA,eAAe,kBAAkB,kBAA8C;AAC7E,QAAM,iBAAgC;AAAA,IACpC;AAAA,IACA,yBAAyB;AAAA,IACzB,mBAAmB;AAAA,IACnB,iBAAiB;AAAA,EACnB,GAEM,EAAE,SAAS,MAAM,IAAI,MAAM,OAAO,aAAa;AAerD,SAde,MAAM;AAAA,IACnB,YAAY;AACV,YAAM,YAAY,IAAI,UAAAD,QAAG,OAAO,cAAc;AAC9C,mBAAM,UAAU,QAAQ,GACjB;AAAA,IACT;AAAA,IACA;AAAA,MACE,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,YAAY;AAAA,IACd;AAAA,EACF;AAGF;",
|
|
5
|
+
"names": ["pg", "client"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
33
|
+
}), mod);
|
|
34
|
+
var getDBClient_exports = {};
|
|
35
|
+
__export(getDBClient_exports, {
|
|
36
|
+
getDBClient: () => getDBClient,
|
|
37
|
+
getNewClient: () => getNewClient,
|
|
38
|
+
queryDb: () => queryDb
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(getDBClient_exports);
|
|
41
|
+
var import_pg = __toESM(require("pg"), 1);
|
|
42
|
+
function _instanceof(left, right) {
|
|
43
|
+
return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
|
|
44
|
+
}
|
|
45
|
+
var cache = /* @__PURE__ */new Map(),
|
|
46
|
+
createPoolKey = function (connectionString) {
|
|
47
|
+
return connectionString;
|
|
48
|
+
},
|
|
49
|
+
getOrCreatePoolCache = function (connectionString, config) {
|
|
50
|
+
var key = createPoolKey(connectionString);
|
|
51
|
+
return cache.has(key) || cache.set(key, {
|
|
52
|
+
pool: new import_pg.default.Pool(config),
|
|
53
|
+
maxConnections: null,
|
|
54
|
+
reservedConnections: null,
|
|
55
|
+
openedConnections: null,
|
|
56
|
+
openedConnectionsLastUpdate: null
|
|
57
|
+
}), cache.get(key);
|
|
58
|
+
};
|
|
59
|
+
async function getDBClient() {
|
|
60
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {},
|
|
61
|
+
{
|
|
62
|
+
pool,
|
|
63
|
+
connectionString,
|
|
64
|
+
retries = 8
|
|
65
|
+
} = options;
|
|
66
|
+
if (!pool && !connectionString) throw new Error("Either pool or connectionString must be provided");
|
|
67
|
+
var client = null;
|
|
68
|
+
try {
|
|
69
|
+
return client = await tryToGetNewClientFromPool(pool, connectionString, retries), client;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw console.error("Failed to get DB client:", error), error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function tryToGetNewClientFromPool(providedPool, connectionString, retries) {
|
|
75
|
+
var {
|
|
76
|
+
default: retry
|
|
77
|
+
} = await import("async-retry"),
|
|
78
|
+
clientFromPool = await retry(async function () {
|
|
79
|
+
if (providedPool) {
|
|
80
|
+
console.info("Connecting to provided pool...");
|
|
81
|
+
var client = await providedPool.connect();
|
|
82
|
+
return console.info("Connected to pool"), client;
|
|
83
|
+
}
|
|
84
|
+
if (!connectionString) throw new Error("No connection string provided");
|
|
85
|
+
var configurations = {
|
|
86
|
+
connectionString,
|
|
87
|
+
connectionTimeoutMillis: 5e3,
|
|
88
|
+
// idle_session_timeout set to 35s on server, client timeout at 30s
|
|
89
|
+
// fix via https://github.com/brianc/node-postgres/issues/2718#issuecomment-2094885323
|
|
90
|
+
idleTimeoutMillis: 3e4,
|
|
91
|
+
allowExitOnIdle: !0
|
|
92
|
+
},
|
|
93
|
+
poolCache = getOrCreatePoolCache(connectionString, configurations);
|
|
94
|
+
console.info(`Connecting to pool ${connectionString}...`);
|
|
95
|
+
var client1 = await poolCache.pool.connect();
|
|
96
|
+
return console.info("Connected to pool"), client1;
|
|
97
|
+
}, {
|
|
98
|
+
retries,
|
|
99
|
+
minTimeout: 300,
|
|
100
|
+
factor: 2,
|
|
101
|
+
maxTimeout: 8e3
|
|
102
|
+
});
|
|
103
|
+
return clientFromPool;
|
|
104
|
+
}
|
|
105
|
+
async function queryDb(queryText, params) {
|
|
106
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {},
|
|
107
|
+
client = null;
|
|
108
|
+
try {
|
|
109
|
+
return client = await tryToGetNewClientFromPool(options.pool, options.connectionString, options.retries || 8), await client.query(queryText, params);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw console.error("Database query failed:", {
|
|
112
|
+
query: queryText,
|
|
113
|
+
error: _instanceof(error, Error) ? error.message : String(error)
|
|
114
|
+
}), error;
|
|
115
|
+
} finally {
|
|
116
|
+
if (client && options.connectionString) {
|
|
117
|
+
var tooManyConnections = await checkForTooManyConnections(client, options.connectionString);
|
|
118
|
+
if (tooManyConnections) {
|
|
119
|
+
var poolCache = cache.get(createPoolKey(options.connectionString));
|
|
120
|
+
client.release(), await poolCache?.pool.end(), poolCache && cache.delete(createPoolKey(options.connectionString));
|
|
121
|
+
} else client.release();
|
|
122
|
+
} else client && client.release();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function checkForTooManyConnections(client, connectionString) {
|
|
126
|
+
var poolCache = cache.get(createPoolKey(connectionString));
|
|
127
|
+
if (!poolCache) return !1;
|
|
128
|
+
var currentTime = Date.now(),
|
|
129
|
+
openedConnectionsMaxAge = 1e4,
|
|
130
|
+
maxConnectionsTolerance = 0.9;
|
|
131
|
+
if (poolCache.maxConnections === null || poolCache.reservedConnections === null) {
|
|
132
|
+
var [maxConnections, reservedConnections] = await getConnectionLimits(client);
|
|
133
|
+
console.info(`Max connections: ${maxConnections}, Reserved connections: ${reservedConnections}`), poolCache.maxConnections = maxConnections, poolCache.reservedConnections = reservedConnections;
|
|
134
|
+
}
|
|
135
|
+
if (poolCache.openedConnections === null || poolCache.openedConnectionsLastUpdate === null || currentTime - poolCache.openedConnectionsLastUpdate > openedConnectionsMaxAge) {
|
|
136
|
+
var openedConnections = await getOpenedConnections(client, connectionString);
|
|
137
|
+
poolCache.openedConnections = openedConnections, poolCache.openedConnectionsLastUpdate = currentTime;
|
|
138
|
+
}
|
|
139
|
+
return poolCache.openedConnections > (poolCache.maxConnections - poolCache.reservedConnections) * maxConnectionsTolerance ? (console.warn(`Too many connections detected: ${poolCache.openedConnections}/${poolCache.maxConnections - poolCache.reservedConnections}`), !0) : !1;
|
|
140
|
+
}
|
|
141
|
+
async function getConnectionLimits(client) {
|
|
142
|
+
console.info("Getting connection limits...");
|
|
143
|
+
var maxConnectionsResult = await client.query("SHOW max_connections"),
|
|
144
|
+
reservedConnectionResult = await client.query("SHOW superuser_reserved_connections");
|
|
145
|
+
return [Number.parseInt(maxConnectionsResult.rows[0].max_connections, 10), Number.parseInt(reservedConnectionResult.rows[0].superuser_reserved_connections, 10)];
|
|
146
|
+
}
|
|
147
|
+
async function getOpenedConnections(client, connectionString) {
|
|
148
|
+
var _openConnectionsResult_rows_,
|
|
149
|
+
dbName = new URL(connectionString).pathname.slice(1);
|
|
150
|
+
console.info("Getting opened connections...");
|
|
151
|
+
var openConnectionsResult = await client.query("SELECT numbackends as opened_connections FROM pg_stat_database WHERE datname = $1", [dbName]),
|
|
152
|
+
result = Number.parseInt(((_openConnectionsResult_rows_ = openConnectionsResult.rows[0]) === null || _openConnectionsResult_rows_ === void 0 ? void 0 : _openConnectionsResult_rows_.opened_connections) || 0, 10);
|
|
153
|
+
return console.info(`Opened connections: ${result}`), result;
|
|
154
|
+
}
|
|
155
|
+
async function getNewClient() {
|
|
156
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {},
|
|
157
|
+
{
|
|
158
|
+
connectionString
|
|
159
|
+
} = options;
|
|
160
|
+
if (!connectionString) throw new Error("connectionString is required for getNewClient");
|
|
161
|
+
try {
|
|
162
|
+
var client = await tryToGetNewClient(connectionString);
|
|
163
|
+
return client;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw console.error("Failed to get new client:", error), error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function tryToGetNewClient(connectionString) {
|
|
169
|
+
var configurations = {
|
|
170
|
+
connectionString,
|
|
171
|
+
connectionTimeoutMillis: 5e3,
|
|
172
|
+
idleTimeoutMillis: 3e4,
|
|
173
|
+
allowExitOnIdle: !0
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
default: retry
|
|
177
|
+
} = await import("async-retry"),
|
|
178
|
+
client = await retry(async function () {
|
|
179
|
+
var newClient = new import_pg.default.Client(configurations);
|
|
180
|
+
return await newClient.connect(), newClient;
|
|
181
|
+
}, {
|
|
182
|
+
retries: 10,
|
|
183
|
+
minTimeout: 100,
|
|
184
|
+
factor: 2,
|
|
185
|
+
maxTimeout: 5e3
|
|
186
|
+
});
|
|
187
|
+
return client;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=getDBClient.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","getDBClient_exports","__export","getDBClient","getNewClient","queryDb","module","exports","import_pg","__toESM","require","_instanceof","left","right","Symbol","hasInstance","cache","Map","createPoolKey","connectionString","getOrCreatePoolCache","config","key","has","set","pool","default","Pool","maxConnections","reservedConnections","openedConnections","openedConnectionsLastUpdate","get","options","arguments","length","retries","Error","client","tryToGetNewClientFromPool","error","console","providedPool","retry","clientFromPool","info","connect","configurations","connectionTimeoutMillis","idleTimeoutMillis","allowExitOnIdle","poolCache","client1","minTimeout","factor","maxTimeout","queryText","params","query","message","String","tooManyConnections","checkForTooManyConnections","release","end","delete","currentTime","Date","now","openedConnectionsMaxAge","maxConnectionsTolerance","getConnectionLimits","getOpenedConnections","warn","maxConnectionsResult","reservedConnectionResult","Number","parseInt","rows","max_connections","superuser_reserved_connections","_openConnectionsResult_rows_","dbName","URL","pathname","slice","openConnectionsResult","result","opened_connections","tryToGetNewClient","newClient","Client"],"sources":["../../../src/helpers/getDBClient.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,YAAA,EAAAA,CAAA,KAAAA,YAAA;EAAAC,OAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAA+CX,YAAA,CAAAK,mBAAA;AAY/C,IAAAO,SAAM,GAAQC,OAAA,CAAAC,OAAA,KAAI,GAShB,EAEI;AAGJ,SAAMC,WAAMA,CAAAC,IAAA,EAAAC,KAAc;EAE1B,OAAKA,KAAA,IAAM,IAAO,WACVC,MAAI,GAAK,OAAAD,KAAA,CAAAC,MAAA,CAAAC,WAAA,MAAAF,KAAA,CAAAC,MAAA,CAAAC,WAAA,EAAAH,IAAA,IAAAA,IAAA,YAAAC,KAAA;AAAA;AACW,IACxBG,KAAA,kBAAgB,IAAAC,GAAA;EAAAC,aAAA,YAAAA,CAAAC,gBAAA;IAAA,OAChBA,gBAAqB;EAAA;EAAAC,oBACF,YAAAA,CAAAD,gBAAA,EAAAE,MAAA;IAAA,IACnBC,GAAA,GAAAJ,aAAA,CAAAC,gBAA6B;IAC/B,OAGKH,KAAM,CAAAO,GAAI,CAAGD,GAAA,KAAAN,KAAA,CAAAQ,GAAA,CAAAF,GAAA;MACtBG,IAAA,MAAAjB,SAAA,CAAAkB,OA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B,UAAA;MAEAC,MAAA;MACEC,UAAM;IAAgC,EACpC;EAAA,OACAjB,MAAA;AAAyB","ignoreList":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
createDb: () => createDb,
|
|
35
|
+
createPool: () => createPool,
|
|
36
|
+
createServerHelpers: () => import_createServerHelpers.createServerHelpers,
|
|
37
|
+
createSql: () => import_sql.createSql,
|
|
38
|
+
getDBClient: () => import_getDBClient.getDBClient,
|
|
39
|
+
processInChunks: () => import_chunkedQuery.processInChunks,
|
|
40
|
+
queryDb: () => import_getDBClient.queryDb,
|
|
41
|
+
updateInChunks: () => import_chunkedQuery.updateInChunks
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
var import_node_postgres = require("drizzle-orm/node-postgres"),
|
|
45
|
+
import_pg = __toESM(require("pg"), 1),
|
|
46
|
+
import_sql = require("./sql.cjs"),
|
|
47
|
+
import_createServerHelpers = require("./createServerHelpers.cjs"),
|
|
48
|
+
import_getDBClient = require("./helpers/getDBClient.cjs"),
|
|
49
|
+
import_chunkedQuery = require("./helpers/chunkedQuery.cjs");
|
|
50
|
+
const createPool = connectionString => new import_pg.default.Pool({
|
|
51
|
+
connectionString
|
|
52
|
+
}),
|
|
53
|
+
createDb = (connectionString, schema) => {
|
|
54
|
+
const pool = createPool(connectionString);
|
|
55
|
+
return (0, import_node_postgres.drizzle)(pool, {
|
|
56
|
+
schema,
|
|
57
|
+
logger: !1
|
|
58
|
+
});
|
|
59
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
createDb: () => createDb,
|
|
26
|
+
createPool: () => createPool,
|
|
27
|
+
createServerHelpers: () => import_createServerHelpers.createServerHelpers,
|
|
28
|
+
createSql: () => import_sql.createSql,
|
|
29
|
+
getDBClient: () => import_getDBClient.getDBClient,
|
|
30
|
+
processInChunks: () => import_chunkedQuery.processInChunks,
|
|
31
|
+
queryDb: () => import_getDBClient.queryDb,
|
|
32
|
+
updateInChunks: () => import_chunkedQuery.updateInChunks
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_node_postgres = require("drizzle-orm/node-postgres"), import_pg = __toESM(require("pg"), 1), import_sql = require("./sql"), import_createServerHelpers = require("./createServerHelpers"), import_getDBClient = require("./helpers/getDBClient"), import_chunkedQuery = require("./helpers/chunkedQuery");
|
|
36
|
+
const createPool = (connectionString) => new import_pg.default.Pool({
|
|
37
|
+
connectionString
|
|
38
|
+
}), createDb = (connectionString, schema) => {
|
|
39
|
+
const pool = createPool(connectionString);
|
|
40
|
+
return (0, import_node_postgres.drizzle)(pool, {
|
|
41
|
+
schema,
|
|
42
|
+
logger: !1
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAwB,sCAExB,YAAe,2BAsBf,aAAyC,kBAEzC,6BAAwD,kCAExD,qBAIO,kCAEP,sBAAgD;AA9BzC,MAAM,aAAa,CAAC,qBAClB,IAAI,UAAAA,QAAG,KAAK;AAAA,EACjB;AACF,CAAC,GAGU,WAAW,CACtB,kBACA,WAC4B;AAC5B,QAAM,OAAO,WAAW,gBAAgB;AACxC,aAAO,8BAAQ,MAAM;AAAA,IACnB;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACH;",
|
|
5
|
+
"names": ["pg"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
33
|
+
}), mod);
|
|
34
|
+
var index_exports = {};
|
|
35
|
+
__export(index_exports, {
|
|
36
|
+
createDb: () => createDb,
|
|
37
|
+
createPool: () => createPool,
|
|
38
|
+
createServerHelpers: () => import_createServerHelpers.createServerHelpers,
|
|
39
|
+
createSql: () => import_sql.createSql,
|
|
40
|
+
getDBClient: () => import_getDBClient.getDBClient,
|
|
41
|
+
processInChunks: () => import_chunkedQuery.processInChunks,
|
|
42
|
+
queryDb: () => import_getDBClient.queryDb,
|
|
43
|
+
updateInChunks: () => import_chunkedQuery.updateInChunks
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(index_exports);
|
|
46
|
+
var import_node_postgres = require("drizzle-orm/node-postgres"),
|
|
47
|
+
import_pg = __toESM(require("pg"), 1),
|
|
48
|
+
import_sql = require("./sql.native.js"),
|
|
49
|
+
import_createServerHelpers = require("./createServerHelpers.native.js"),
|
|
50
|
+
import_getDBClient = require("./helpers/getDBClient.native.js"),
|
|
51
|
+
import_chunkedQuery = require("./helpers/chunkedQuery.native.js"),
|
|
52
|
+
createPool = function (connectionString) {
|
|
53
|
+
return new import_pg.default.Pool({
|
|
54
|
+
connectionString
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
createDb = function (connectionString, schema) {
|
|
58
|
+
var pool = createPool(connectionString);
|
|
59
|
+
return (0, import_node_postgres.drizzle)(pool, {
|
|
60
|
+
schema,
|
|
61
|
+
logger: !1
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","createDb","createPool","createServerHelpers","import_createServerHelpers","createSql","import_sql","getDBClient","import_getDBClient","processInChunks","import_chunkedQuery","queryDb","updateInChunks","module","exports","import_node_postgres","require","import_pg","__toESM","connectionString","default","Pool","schema","pool","drizzle","logger"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA,QAAA;EAAAC,UAAA,EAAAA,CAAA,KAAAA,UAAA;EAAAC,mBAAA,EAAAA,CAAA,KAAAC,0BAAA,CAAAD,mBAAA;EAAAE,SAAA,EAAAA,CAAA,KAAAC,UAAA,CAAAD,SAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAC,kBAAA,CAAAD,WAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAC,mBAAA,CAAAD,eAAA;EAAAE,OAAA,EAAAA,CAAA,KAAAH,kBAAA,CAAAG,OAAA;EAAAC,cAAA,EAAAA,CAAA,KAAAF,mBAAA,CAAAE;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAApB,YAAwB,CAAAK,aAAA;AAIjB,IAAAgB,oBAAoB,GAAAC,OAAA,4BACd,CAAG;EAAAC,SAAK,GAAAC,OAAA,CAAAF,OAAA;EAAAV,UAAA,GAAAU,OAAA;EAAAZ,0BAAA,GAAAY,OAAA;EAAAR,kBAAA,GAAAQ,OAAA;EAAAN,mBAAA,GAAAM,OAAA;EAAAd,UAAA,YAAAA,CAAAiB,gBAAA;IACjB,WAAAF,SAAA,CAAAG,OAAA,CAAAC,IAAA;MAISF;IAIX;EACA;EAAAlB,QAAA,GAAO,SAAAA,CAAAkB,gBAAA,EAAAG,MAAQ,EAAM;IAAA,IACnBC,IAAA,GAAArB,UAAA,CAAAiB,gBAAA;IAAA,OACA,IAAQJ,oBAAA,CAAAS,OAAA,EAAAD,IAAA;MACTD,MAAA;MACHG,MAAA","ignoreList":[]}
|