@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,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var import_citty = require("citty"),
|
|
5
|
+
import_path = require("path"),
|
|
6
|
+
import_build_migrations = require("./scripts/build-migrations.native.js"),
|
|
7
|
+
import_drizzle_migrations_sync = require("./scripts/drizzle-migrations-sync.native.js"),
|
|
8
|
+
import_migration_add = require("./scripts/migration-add.native.js"),
|
|
9
|
+
import_pg_dump = require("./scripts/pg_dump.native.js"),
|
|
10
|
+
import_psql = require("./scripts/psql.native.js"),
|
|
11
|
+
syncDrizzle = (0, import_citty.defineCommand)({
|
|
12
|
+
meta: {
|
|
13
|
+
name: "sync-drizzle",
|
|
14
|
+
description: "Sync Drizzle SQL migrations to TypeScript wrappers"
|
|
15
|
+
},
|
|
16
|
+
args: {
|
|
17
|
+
dir: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Migrations directory",
|
|
20
|
+
required: !1,
|
|
21
|
+
default: "./src/database/migrations"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
async run(param) {
|
|
25
|
+
var {
|
|
26
|
+
args
|
|
27
|
+
} = param,
|
|
28
|
+
migrationsDir = (0, import_path.join)(process.cwd(), args.dir);
|
|
29
|
+
console.info(`Syncing migrations in ${migrationsDir}`), await (0, import_drizzle_migrations_sync.syncDrizzleMigrations)({
|
|
30
|
+
migrationsDir
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
buildMigrations = (0, import_citty.defineCommand)({
|
|
35
|
+
meta: {
|
|
36
|
+
name: "build-migrations",
|
|
37
|
+
description: "Build migration bundle for deployment"
|
|
38
|
+
},
|
|
39
|
+
args: {
|
|
40
|
+
dir: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "Migrations directory",
|
|
43
|
+
required: !1,
|
|
44
|
+
default: "./src/database/migrations"
|
|
45
|
+
},
|
|
46
|
+
out: {
|
|
47
|
+
type: "string",
|
|
48
|
+
description: "Output file name",
|
|
49
|
+
required: !1,
|
|
50
|
+
default: "migrate-dist.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
async run(param) {
|
|
54
|
+
var {
|
|
55
|
+
args
|
|
56
|
+
} = param,
|
|
57
|
+
migrationsDir = (0, import_path.join)(process.cwd(), args.dir);
|
|
58
|
+
await (0, import_build_migrations.buildMigrations)({
|
|
59
|
+
migrationsDir,
|
|
60
|
+
outFile: args.out
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
migrationAdd = (0, import_citty.defineCommand)({
|
|
65
|
+
meta: {
|
|
66
|
+
name: "migrate:add",
|
|
67
|
+
description: "Create a new custom TypeScript migration"
|
|
68
|
+
},
|
|
69
|
+
args: {
|
|
70
|
+
name: {
|
|
71
|
+
type: "positional",
|
|
72
|
+
description: "Migration name",
|
|
73
|
+
required: !1
|
|
74
|
+
},
|
|
75
|
+
dir: {
|
|
76
|
+
type: "string",
|
|
77
|
+
description: "Migrations directory",
|
|
78
|
+
required: !1,
|
|
79
|
+
default: "./src/database/migrations"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
async run(param) {
|
|
83
|
+
var {
|
|
84
|
+
args
|
|
85
|
+
} = param,
|
|
86
|
+
migrationsDir = (0, import_path.join)(process.cwd(), args.dir);
|
|
87
|
+
(0, import_migration_add.addMigration)({
|
|
88
|
+
migrationsDir,
|
|
89
|
+
name: args.name
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
psql = (0, import_citty.defineCommand)({
|
|
94
|
+
meta: {
|
|
95
|
+
name: "psql",
|
|
96
|
+
description: "Connect to PostgreSQL database with psql"
|
|
97
|
+
},
|
|
98
|
+
args: {
|
|
99
|
+
connectionString: {
|
|
100
|
+
type: "string",
|
|
101
|
+
description: "PostgreSQL connection string",
|
|
102
|
+
required: !1
|
|
103
|
+
},
|
|
104
|
+
query: {
|
|
105
|
+
type: "string",
|
|
106
|
+
description: "Query to execute",
|
|
107
|
+
required: !1
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async run(param) {
|
|
111
|
+
var {
|
|
112
|
+
args
|
|
113
|
+
} = param,
|
|
114
|
+
connectionString = args.connectionString || process.env.ZERO_UPSTREAM_DB;
|
|
115
|
+
connectionString || (console.error("No connection string provided. Set ZERO_UPSTREAM_DB or pass --connectionString"), process.exit(1));
|
|
116
|
+
var exitCode = (0, import_psql.runPsql)({
|
|
117
|
+
connectionString,
|
|
118
|
+
query: args.query
|
|
119
|
+
});
|
|
120
|
+
process.exit(exitCode || 0);
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
pgDump = (0, import_citty.defineCommand)({
|
|
124
|
+
meta: {
|
|
125
|
+
name: "pg_dump",
|
|
126
|
+
description: "Dump PostgreSQL database using pg_dump"
|
|
127
|
+
},
|
|
128
|
+
args: {
|
|
129
|
+
connectionString: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "PostgreSQL connection string",
|
|
132
|
+
required: !1
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
async run(param) {
|
|
136
|
+
var {
|
|
137
|
+
args
|
|
138
|
+
} = param,
|
|
139
|
+
connectionString = args.connectionString || process.env.ZERO_UPSTREAM_DB;
|
|
140
|
+
connectionString || (console.error("No connection string provided. Set ZERO_UPSTREAM_DB or pass --connectionString"), process.exit(1));
|
|
141
|
+
var cliArgs = process.argv.slice(3),
|
|
142
|
+
exitCode = (0, import_pg_dump.runPgDump)({
|
|
143
|
+
connectionString,
|
|
144
|
+
args: cliArgs
|
|
145
|
+
});
|
|
146
|
+
process.exit(exitCode || 0);
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
main = (0, import_citty.defineCommand)({
|
|
150
|
+
meta: {
|
|
151
|
+
name: "postgres",
|
|
152
|
+
description: "PostgreSQL database utilities and migration tools",
|
|
153
|
+
version: "0.0.1"
|
|
154
|
+
},
|
|
155
|
+
subCommands: {
|
|
156
|
+
"sync-drizzle": syncDrizzle,
|
|
157
|
+
"build-migrations": buildMigrations,
|
|
158
|
+
"migrate:add": migrationAdd,
|
|
159
|
+
psql,
|
|
160
|
+
pg_dump: pgDump
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
(0, import_citty.runMain)(main);
|
|
164
|
+
//# sourceMappingURL=cli.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["import_citty","require","import_path","import_build_migrations","import_drizzle_migrations_sync","import_migration_add","import_pg_dump","import_psql","syncDrizzle","defineCommand","meta","name","description","args","dir","type","required","default","run","param","migrationsDir","join","process","cwd","console","info","syncDrizzleMigrations","buildMigrations","out","outFile","migrationAdd","addMigration","psql","connectionString","query","env","ZERO_UPSTREAM_DB","error","exit","exitCode","runPsql","pgDump","cliArgs","argv","slice","runPgDump","main","version","subCommands"],"sources":["../../src/cli.ts"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var createServerHelpers_exports = {};
|
|
22
|
+
__export(createServerHelpers_exports, {
|
|
23
|
+
createServerHelpers: () => createServerHelpers
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(createServerHelpers_exports);
|
|
26
|
+
var import_sql = require("./sql.cjs"),
|
|
27
|
+
import_getDBClient = require("./helpers/getDBClient.cjs");
|
|
28
|
+
function createServerHelpers(pool) {
|
|
29
|
+
const sql = (0, import_sql.createSql)(pool);
|
|
30
|
+
return (0, import_sql.setDefaultPool)(pool), {
|
|
31
|
+
sql,
|
|
32
|
+
getDBClient: (options = {}) => (0, import_getDBClient.getDBClient)({
|
|
33
|
+
pool,
|
|
34
|
+
...options
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var createServerHelpers_exports = {};
|
|
16
|
+
__export(createServerHelpers_exports, {
|
|
17
|
+
createServerHelpers: () => createServerHelpers
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(createServerHelpers_exports);
|
|
20
|
+
var import_sql = require("./sql"), import_getDBClient = require("./helpers/getDBClient");
|
|
21
|
+
function createServerHelpers(pool) {
|
|
22
|
+
const sql = (0, import_sql.createSql)(pool);
|
|
23
|
+
return (0, import_sql.setDefaultPool)(pool), {
|
|
24
|
+
sql,
|
|
25
|
+
getDBClient: (options = {}) => (0, import_getDBClient.getDBClient)({ pool, ...options })
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=createServerHelpers.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createServerHelpers.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA0C,kBAC1C,qBAAqD;AAS9C,SAAS,oBAAoB,MAA2B;AAC7D,QAAM,UAAM,sBAAU,IAAI;AAC1B,wCAAe,IAAI,GAEZ;AAAA,IACL;AAAA,IACA,aAAa,CAAC,UAAU,CAAC,UAAM,gCAAY,EAAE,MAAM,GAAG,QAAQ,CAAC;AAAA,EACjE;AACF;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __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 __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var createServerHelpers_exports = {};
|
|
24
|
+
__export(createServerHelpers_exports, {
|
|
25
|
+
createServerHelpers: () => createServerHelpers
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(createServerHelpers_exports);
|
|
28
|
+
var import_sql = require("./sql.native.js"),
|
|
29
|
+
import_getDBClient = require("./helpers/getDBClient.native.js");
|
|
30
|
+
function createServerHelpers(pool) {
|
|
31
|
+
var sql = (0, import_sql.createSql)(pool);
|
|
32
|
+
return (0, import_sql.setDefaultPool)(pool), {
|
|
33
|
+
sql,
|
|
34
|
+
getDBClient: function () {
|
|
35
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
36
|
+
return (0, import_getDBClient.getDBClient)({
|
|
37
|
+
pool,
|
|
38
|
+
...options
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=createServerHelpers.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createServerHelpers_exports","__export","createServerHelpers","module","exports","import_sql","require","import_getDBClient","pool","sql","createSql","setDefaultPool","getDBClient","options","arguments","length"],"sources":["../../src/createServerHelpers.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,2BAAA;AAAAC,QAAA,CAAAD,2BAAA;EAAAE,mBAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAA0CT,YAAA,CAAAK,2BACW;AAS9C,IAAAK,UAAS,GAAAC,OAAA,kBAAoB;EAA2BC,kBAAA,GAAAD,OAAA;AAC7D,SAAMJ,mBAAMA,CAAAM,IAAA;EACZ,IAAAC,GAAA,OAAAJ,UAAA,CAAAK,SAAA,EAAAF,IAAe;EAER,OACL,IAAAH,UAAA,CAAAM,cAAA,EAAAH,IAAA;IACAC,GAAA;IACFG,WAAA,WAAAA,CAAA;MACF,IAAAC,OAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA","ignoreList":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var chunkedQuery_exports = {};
|
|
22
|
+
__export(chunkedQuery_exports, {
|
|
23
|
+
processInChunks: () => processInChunks,
|
|
24
|
+
updateInChunks: () => updateInChunks
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(chunkedQuery_exports);
|
|
27
|
+
async function processInChunks(client, query, processor, options = {}) {
|
|
28
|
+
const {
|
|
29
|
+
chunkSize = 1e3,
|
|
30
|
+
onProgress
|
|
31
|
+
} = options;
|
|
32
|
+
let offset = 0,
|
|
33
|
+
hasMore = !0,
|
|
34
|
+
totalProcessed = 0;
|
|
35
|
+
const countQuery = query.replace(/SELECT .+ FROM/, "SELECT COUNT(*) FROM").replace(/ORDER BY .+/, ""),
|
|
36
|
+
countResult = await client.query(countQuery),
|
|
37
|
+
totalCount = Number.parseInt(countResult.rows[0].count, 10);
|
|
38
|
+
for (; hasMore;) {
|
|
39
|
+
const paginatedQuery = `${query} LIMIT ${chunkSize} OFFSET ${offset}`,
|
|
40
|
+
result = await client.query(paginatedQuery);
|
|
41
|
+
if (result.rows.length === 0) {
|
|
42
|
+
hasMore = !1;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
await processor(result.rows), totalProcessed += result.rows.length, offset += chunkSize, onProgress && onProgress(totalProcessed, totalCount), result.rows.length < chunkSize && (hasMore = !1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function updateInChunks(client, tableName, selectQuery, transformer, options = {}) {
|
|
49
|
+
let totalUpdated = 0;
|
|
50
|
+
return await processInChunks(client, selectQuery, async rows => {
|
|
51
|
+
for (const row of rows) {
|
|
52
|
+
const updates = await transformer(row);
|
|
53
|
+
if (updates && Object.keys(updates).length > 0) {
|
|
54
|
+
const setClause = Object.keys(updates).map((key, index) => `${key} = $${index + 2}`).join(", "),
|
|
55
|
+
values = [row.id, ...Object.values(updates)];
|
|
56
|
+
await client.query(`UPDATE ${tableName} SET ${setClause} WHERE id = $1`, values), totalUpdated++;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, options), totalUpdated;
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var chunkedQuery_exports = {};
|
|
16
|
+
__export(chunkedQuery_exports, {
|
|
17
|
+
processInChunks: () => processInChunks,
|
|
18
|
+
updateInChunks: () => updateInChunks
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(chunkedQuery_exports);
|
|
21
|
+
async function processInChunks(client, query, processor, options = {}) {
|
|
22
|
+
const { chunkSize = 1e3, onProgress } = options;
|
|
23
|
+
let offset = 0, hasMore = !0, totalProcessed = 0;
|
|
24
|
+
const countQuery = query.replace(/SELECT .+ FROM/, "SELECT COUNT(*) FROM").replace(/ORDER BY .+/, ""), countResult = await client.query(countQuery), totalCount = Number.parseInt(countResult.rows[0].count, 10);
|
|
25
|
+
for (; hasMore; ) {
|
|
26
|
+
const paginatedQuery = `${query} LIMIT ${chunkSize} OFFSET ${offset}`, result = await client.query(paginatedQuery);
|
|
27
|
+
if (result.rows.length === 0) {
|
|
28
|
+
hasMore = !1;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
await processor(result.rows), totalProcessed += result.rows.length, offset += chunkSize, onProgress && onProgress(totalProcessed, totalCount), result.rows.length < chunkSize && (hasMore = !1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function updateInChunks(client, tableName, selectQuery, transformer, options = {}) {
|
|
35
|
+
let totalUpdated = 0;
|
|
36
|
+
return await processInChunks(
|
|
37
|
+
client,
|
|
38
|
+
selectQuery,
|
|
39
|
+
async (rows) => {
|
|
40
|
+
for (const row of rows) {
|
|
41
|
+
const updates = await transformer(row);
|
|
42
|
+
if (updates && Object.keys(updates).length > 0) {
|
|
43
|
+
const setClause = Object.keys(updates).map((key, index) => `${key} = $${index + 2}`).join(", "), values = [row.id, ...Object.values(updates)];
|
|
44
|
+
await client.query(`UPDATE ${tableName} SET ${setClause} WHERE id = $1`, values), totalUpdated++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
options
|
|
49
|
+
), totalUpdated;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=chunkedQuery.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/chunkedQuery.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,eAAsB,gBACpB,QACA,OACA,WACA,UAA+B,CAAC,GACjB;AACf,QAAM,EAAE,YAAY,KAAM,WAAW,IAAI;AACzC,MAAI,SAAS,GACT,UAAU,IACV,iBAAiB;AAGrB,QAAM,aAAa,MAChB,QAAQ,kBAAkB,sBAAsB,EAChD,QAAQ,eAAe,EAAE,GACtB,cAAc,MAAM,OAAO,MAAM,UAAU,GAC3C,aAAa,OAAO,SAAS,YAAY,KAAK,CAAC,EAAE,OAAO,EAAE;AAEhE,SAAO,WAAS;AACd,UAAM,iBAAiB,GAAG,KAAK,UAAU,SAAS,WAAW,MAAM,IAC7D,SAAS,MAAM,OAAO,MAAS,cAAc;AAEnD,QAAI,OAAO,KAAK,WAAW,GAAG;AAC5B,gBAAU;AACV;AAAA,IACF;AAEA,UAAM,UAAU,OAAO,IAAI,GAE3B,kBAAkB,OAAO,KAAK,QAC9B,UAAU,WAEN,cACF,WAAW,gBAAgB,UAAU,GAInC,OAAO,KAAK,SAAS,cACvB,UAAU;AAAA,EAEd;AACF;AAKA,eAAsB,eACpB,QACA,WACA,aACA,aACA,UAA+B,CAAC,GACf;AACjB,MAAI,eAAe;AAEnB,eAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,OAAO,SAAS;AACd,iBAAW,OAAO,MAAM;AACtB,cAAM,UAAU,MAAM,YAAY,GAAG;AAErC,YAAI,WAAW,OAAO,KAAK,OAAO,EAAE,SAAS,GAAG;AAE9C,gBAAM,YAAY,OAAO,KAAK,OAAO,EAClC,IAAI,CAAC,KAAK,UAAU,GAAG,GAAG,OAAO,QAAQ,CAAC,EAAE,EAC5C,KAAK,IAAI,GAEN,SAAS,CAAC,IAAI,IAAI,GAAG,OAAO,OAAO,OAAO,CAAC;AAEjD,gBAAM,OAAO,MAAM,UAAU,SAAS,QAAQ,SAAS,kBAAkB,MAAM,GAE/E;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,EACF,GAEO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __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 __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var chunkedQuery_exports = {};
|
|
24
|
+
__export(chunkedQuery_exports, {
|
|
25
|
+
processInChunks: () => processInChunks,
|
|
26
|
+
updateInChunks: () => updateInChunks
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(chunkedQuery_exports);
|
|
29
|
+
async function processInChunks(client, query, processor) {
|
|
30
|
+
for (var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, {
|
|
31
|
+
chunkSize = 1e3,
|
|
32
|
+
onProgress
|
|
33
|
+
} = options, offset = 0, hasMore = !0, totalProcessed = 0, countQuery = query.replace(/SELECT .+ FROM/, "SELECT COUNT(*) FROM").replace(/ORDER BY .+/, ""), countResult = await client.query(countQuery), totalCount = Number.parseInt(countResult.rows[0].count, 10); hasMore;) {
|
|
34
|
+
var paginatedQuery = `${query} LIMIT ${chunkSize} OFFSET ${offset}`,
|
|
35
|
+
result = await client.query(paginatedQuery);
|
|
36
|
+
if (result.rows.length === 0) {
|
|
37
|
+
hasMore = !1;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
await processor(result.rows), totalProcessed += result.rows.length, offset += chunkSize, onProgress && onProgress(totalProcessed, totalCount), result.rows.length < chunkSize && (hasMore = !1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function updateInChunks(client, tableName, selectQuery, transformer) {
|
|
44
|
+
var options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {},
|
|
45
|
+
totalUpdated = 0;
|
|
46
|
+
return await processInChunks(client, selectQuery, async function (rows) {
|
|
47
|
+
var _iteratorNormalCompletion = !0,
|
|
48
|
+
_didIteratorError = !1,
|
|
49
|
+
_iteratorError = void 0;
|
|
50
|
+
try {
|
|
51
|
+
for (var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
52
|
+
var row = _step.value,
|
|
53
|
+
updates = await transformer(row);
|
|
54
|
+
if (updates && Object.keys(updates).length > 0) {
|
|
55
|
+
var setClause = Object.keys(updates).map(function (key, index) {
|
|
56
|
+
return `${key} = $${index + 2}`;
|
|
57
|
+
}).join(", "),
|
|
58
|
+
values = [row.id, ...Object.values(updates)];
|
|
59
|
+
await client.query(`UPDATE ${tableName} SET ${setClause} WHERE id = $1`, values), totalUpdated++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
64
|
+
} finally {
|
|
65
|
+
try {
|
|
66
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
67
|
+
} finally {
|
|
68
|
+
if (_didIteratorError) throw _iteratorError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, options), totalUpdated;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=chunkedQuery.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","chunkedQuery_exports","__export","processInChunks","updateInChunks","module","exports","client","query","processor","options","arguments","length","chunkSize","onProgress","offset","hasMore","totalProcessed","countQuery","replace","countResult","totalCount","Number","parseInt","rows","count","paginatedQuery","result","tableName","selectQuery","transformer","totalUpdated","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","row","updates","Object","keys","setClause","map","key","index","join","values","id","err"],"sources":["../../../src/helpers/chunkedQuery.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAA,eAAA;EAAAC,cAAA,EAAAA,CAAA,KAAAA;AAAA;AAUAC,MAAA,CAAAC,OAAA,GAAsBV,YAAA,CAAAK,oBAGpB;AAGA,eAAQE,eAAkBA,CAAAI,MAAA,EAAWC,KAAI,EAAAC,SAAA;EACzC,KAAI,IAAAC,OACA,GAAAC,SAAU,CAAAC,MACV,QAAAD,SAAiB,iBAAAA,SAAA;MAAAE,SAAA;MAAAC;IAAA,IAAAJ,OAAA,EAAAK,MAAA,MAAAC,OAAA,OAAAC,cAAA,MAAAC,UAAA,GAAAV,KAAA,CAAAW,OAAA,2CAAAA,OAAA,qBAAAC,WAAA,SAAAb,MAAA,CAAAC,KAAA,CAAAU,UAAA,GAAAG,UAAA,GAAAC,MAAA,CAAAC,QAAA,CAAAH,WAAA,CAAAI,IAAA,IAAAC,KAAA,OAAAT,OAAA;IAGrB,IAAMU,cAAa,MAChBlB,KAAA,UAAQK,SAAA,WAAkBE,MAAA;MAAAY,MAC1B,SAAQpB,MAAA,CAAAC,KAAe,CAAAkB,cACpB;IAGN,IAAAC,MAAO,CAAAH,IAAA,CAASZ,MAAA;MACdI,OAAM;MAGN;IACE;IACA,MAAAP,SAAA,CAAAkB,MAAA,CAAAH,IAAA,GAAAP,cAAA,IAAAU,MAAA,CAAAH,IAAA,CAAAZ,MAAA,EAAAG,MAAA,IAAAF,SAAA,EAAAC,UAAA,IAAAA,UAAA,CAAAG,cAAA,EAAAI,UAAA,GAAAM,MAAA,CAAAH,IAAA,CAAAZ,MAAA,GAAAC,SAAA,KAAAG,OAAA;EAAA;AAGF;AAWY,eAEdZ,eAAAG,MAAA,EAAAqB,SAAA,EAAAC,WAAA,EAAAC,WAAA;EACF,IAAApB,OAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;IAAAoB,YAAA;EAKA,aAAsB5B,eACpB,CAAAI,MAAA,EACAsB,WACA,kBACAL,IAAA;IAGA,IAAIQ,yBAAe;MAAAC,iBAAA;MAAAC,cAAA;IAEnB;MACE,SAAAC,SAAA,GAAAX,IAAA,CAAAY,MAAA,CAAAC,QAAA,KAAAC,KAAA,IAAAN,yBAAA,IAAAM,KAAA,GAAAH,SAAA,CAAAI,IAAA,IAAAC,IAAA,GAAAR,yBAAA;QACA,IAAAS,GAAA,GAAAH,KAAA,CAAAtC,KAAA;UAAA0C,OAAA,SAAAZ,WAAA,CAAAW,GAAA;QACA,IAAOC,OAAA,IAASC,MAAA,CAAAC,IAAA,CAAAF,OAAA,EAAA9B,MAAA;UACd,IAAAiC,SAAW,GAAOF,MAAM,CAAAC,IAAA,CAAAF,OAAA,EAAAI,GAAA,WAAAC,GAAA,EAAAC,KAAA;cACtB,OAAM,GAAAD,GAAU,OAAMC,KAAA,MAAY;YAElC,EAAI,CAAAC,IAAA,MAAW;YAAAC,MAAO,IAEpBT,GAAA,CAAMU,EAAA,EAMN,GAAAR,MAAM,CAAAO,MAAO,CAAMR,OAAA,EAGrB;UACF,MAAAnC,MAAA,CAAAC,KAAA,WAAAoB,SAAA,QAAAiB,SAAA,kBAAAK,MAAA,GAAAnB,YAAA;QACF;MACA;IACF,CAEO,QAAAqB,GAAA;MACTnB,iBAAA,OAAAC,cAAA,GAAAkB,GAAA","ignoreList":[]}
|
|
@@ -0,0 +1,172 @@
|
|
|
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 getDBClient_exports = {};
|
|
33
|
+
__export(getDBClient_exports, {
|
|
34
|
+
getDBClient: () => getDBClient,
|
|
35
|
+
getNewClient: () => getNewClient,
|
|
36
|
+
queryDb: () => queryDb
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(getDBClient_exports);
|
|
39
|
+
var import_pg = __toESM(require("pg"), 1);
|
|
40
|
+
const cache = /* @__PURE__ */new Map(),
|
|
41
|
+
createPoolKey = connectionString => connectionString,
|
|
42
|
+
getOrCreatePoolCache = (connectionString, config) => {
|
|
43
|
+
const key = createPoolKey(connectionString);
|
|
44
|
+
return cache.has(key) || cache.set(key, {
|
|
45
|
+
pool: new import_pg.default.Pool(config),
|
|
46
|
+
maxConnections: null,
|
|
47
|
+
reservedConnections: null,
|
|
48
|
+
openedConnections: null,
|
|
49
|
+
openedConnectionsLastUpdate: null
|
|
50
|
+
}), cache.get(key);
|
|
51
|
+
};
|
|
52
|
+
async function getDBClient(options = {}) {
|
|
53
|
+
const {
|
|
54
|
+
pool,
|
|
55
|
+
connectionString,
|
|
56
|
+
retries = 8
|
|
57
|
+
} = options;
|
|
58
|
+
if (!pool && !connectionString) throw new Error("Either pool or connectionString must be provided");
|
|
59
|
+
let client = null;
|
|
60
|
+
try {
|
|
61
|
+
return client = await tryToGetNewClientFromPool(pool, connectionString, retries), client;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw console.error("Failed to get DB client:", error), error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function tryToGetNewClientFromPool(providedPool, connectionString, retries) {
|
|
67
|
+
const {
|
|
68
|
+
default: retry
|
|
69
|
+
} = await import("async-retry");
|
|
70
|
+
return await retry(async () => {
|
|
71
|
+
if (providedPool) {
|
|
72
|
+
console.info("Connecting to provided pool...");
|
|
73
|
+
const client2 = await providedPool.connect();
|
|
74
|
+
return console.info("Connected to pool"), client2;
|
|
75
|
+
}
|
|
76
|
+
if (!connectionString) throw new Error("No connection string provided");
|
|
77
|
+
const poolCache = getOrCreatePoolCache(connectionString, {
|
|
78
|
+
connectionString,
|
|
79
|
+
connectionTimeoutMillis: 5e3,
|
|
80
|
+
// idle_session_timeout set to 35s on server, client timeout at 30s
|
|
81
|
+
// fix via https://github.com/brianc/node-postgres/issues/2718#issuecomment-2094885323
|
|
82
|
+
idleTimeoutMillis: 3e4,
|
|
83
|
+
allowExitOnIdle: !0
|
|
84
|
+
});
|
|
85
|
+
console.info(`Connecting to pool ${connectionString}...`);
|
|
86
|
+
const client = await poolCache.pool.connect();
|
|
87
|
+
return console.info("Connected to pool"), client;
|
|
88
|
+
}, {
|
|
89
|
+
retries,
|
|
90
|
+
minTimeout: 300,
|
|
91
|
+
factor: 2,
|
|
92
|
+
maxTimeout: 8e3
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function queryDb(queryText, params, options = {}) {
|
|
96
|
+
let client = null;
|
|
97
|
+
try {
|
|
98
|
+
return client = await tryToGetNewClientFromPool(options.pool, options.connectionString, options.retries || 8), await client.query(queryText, params);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw console.error("Database query failed:", {
|
|
101
|
+
query: queryText,
|
|
102
|
+
error: error instanceof Error ? error.message : String(error)
|
|
103
|
+
}), error;
|
|
104
|
+
} finally {
|
|
105
|
+
if (client && options.connectionString) {
|
|
106
|
+
if (await checkForTooManyConnections(client, options.connectionString)) {
|
|
107
|
+
const poolCache = cache.get(createPoolKey(options.connectionString));
|
|
108
|
+
client.release(), await poolCache?.pool.end(), poolCache && cache.delete(createPoolKey(options.connectionString));
|
|
109
|
+
} else client.release();
|
|
110
|
+
} else client && client.release();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function checkForTooManyConnections(client, connectionString) {
|
|
114
|
+
const poolCache = cache.get(createPoolKey(connectionString));
|
|
115
|
+
if (!poolCache) return !1;
|
|
116
|
+
const currentTime = Date.now(),
|
|
117
|
+
openedConnectionsMaxAge = 1e4,
|
|
118
|
+
maxConnectionsTolerance = 0.9;
|
|
119
|
+
if (poolCache.maxConnections === null || poolCache.reservedConnections === null) {
|
|
120
|
+
const [maxConnections, reservedConnections] = await getConnectionLimits(client);
|
|
121
|
+
console.info(`Max connections: ${maxConnections}, Reserved connections: ${reservedConnections}`), poolCache.maxConnections = maxConnections, poolCache.reservedConnections = reservedConnections;
|
|
122
|
+
}
|
|
123
|
+
if (poolCache.openedConnections === null || poolCache.openedConnectionsLastUpdate === null || currentTime - poolCache.openedConnectionsLastUpdate > openedConnectionsMaxAge) {
|
|
124
|
+
const openedConnections = await getOpenedConnections(client, connectionString);
|
|
125
|
+
poolCache.openedConnections = openedConnections, poolCache.openedConnectionsLastUpdate = currentTime;
|
|
126
|
+
}
|
|
127
|
+
return poolCache.openedConnections > (poolCache.maxConnections - poolCache.reservedConnections) * maxConnectionsTolerance ? (console.warn(`Too many connections detected: ${poolCache.openedConnections}/${poolCache.maxConnections - poolCache.reservedConnections}`), !0) : !1;
|
|
128
|
+
}
|
|
129
|
+
async function getConnectionLimits(client) {
|
|
130
|
+
console.info("Getting connection limits...");
|
|
131
|
+
const maxConnectionsResult = await client.query("SHOW max_connections"),
|
|
132
|
+
reservedConnectionResult = await client.query("SHOW superuser_reserved_connections");
|
|
133
|
+
return [Number.parseInt(maxConnectionsResult.rows[0].max_connections, 10), Number.parseInt(reservedConnectionResult.rows[0].superuser_reserved_connections, 10)];
|
|
134
|
+
}
|
|
135
|
+
async function getOpenedConnections(client, connectionString) {
|
|
136
|
+
const dbName = new URL(connectionString).pathname.slice(1);
|
|
137
|
+
console.info("Getting opened connections...");
|
|
138
|
+
const openConnectionsResult = await client.query("SELECT numbackends as opened_connections FROM pg_stat_database WHERE datname = $1", [dbName]),
|
|
139
|
+
result = Number.parseInt(openConnectionsResult.rows[0]?.opened_connections || 0, 10);
|
|
140
|
+
return console.info(`Opened connections: ${result}`), result;
|
|
141
|
+
}
|
|
142
|
+
async function getNewClient(options = {}) {
|
|
143
|
+
const {
|
|
144
|
+
connectionString
|
|
145
|
+
} = options;
|
|
146
|
+
if (!connectionString) throw new Error("connectionString is required for getNewClient");
|
|
147
|
+
try {
|
|
148
|
+
return await tryToGetNewClient(connectionString);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
throw console.error("Failed to get new client:", error), error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function tryToGetNewClient(connectionString) {
|
|
154
|
+
const configurations = {
|
|
155
|
+
connectionString,
|
|
156
|
+
connectionTimeoutMillis: 5e3,
|
|
157
|
+
idleTimeoutMillis: 3e4,
|
|
158
|
+
allowExitOnIdle: !0
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
default: retry
|
|
162
|
+
} = await import("async-retry");
|
|
163
|
+
return await retry(async () => {
|
|
164
|
+
const newClient = new import_pg.default.Client(configurations);
|
|
165
|
+
return await newClient.connect(), newClient;
|
|
166
|
+
}, {
|
|
167
|
+
retries: 10,
|
|
168
|
+
minTimeout: 100,
|
|
169
|
+
factor: 2,
|
|
170
|
+
maxTimeout: 5e3
|
|
171
|
+
});
|
|
172
|
+
}
|