@mrnafisia/type-query 1.0.16 → 1.0.17
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/README.md +2 -2
- package/dist/U.d.ts +2 -2
- package/dist/U.js +27 -27
- package/dist/context.d.ts +5 -5
- package/dist/context.js +85 -85
- package/dist/dictionary.d.ts +12 -12
- package/dist/dictionary.js +177 -177
- package/dist/entity.d.ts +2589 -2589
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +970 -970
- package/dist/entity.js.map +1 -1
- package/dist/error.d.ts +4 -4
- package/dist/error.js +6 -6
- package/dist/index.d.ts +30 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -30
- package/dist/index.js.map +1 -1
- package/dist/pool.d.ts +5 -5
- package/dist/pool.js +120 -120
- package/dist/schema.d.ts +25 -25
- package/dist/schema.js +395 -395
- package/dist/schema.js.map +1 -1
- package/dist/testUtil.d.ts +4 -0
- package/dist/testUtil.d.ts.map +1 -0
- package/dist/testUtil.js +329 -0
- package/dist/testUtil.js.map +1 -0
- package/dist/types/context.d.ts +55 -55
- package/dist/types/context.js +2 -2
- package/dist/types/entity.d.ts +70 -70
- package/dist/types/entity.d.ts.map +1 -1
- package/dist/types/entity.js +2 -2
- package/dist/types/json.d.ts +8 -8
- package/dist/types/json.js +2 -2
- package/dist/types/model.d.ts +11 -11
- package/dist/types/model.js +2 -2
- package/dist/types/pool.d.ts +18 -18
- package/dist/types/pool.js +2 -2
- package/dist/types/postgres.d.ts +9 -9
- package/dist/types/postgres.js +2 -2
- package/dist/types/table.d.ts +238 -238
- package/dist/types/table.js +2 -2
- package/dist/types/testUtil.d.ts +26 -0
- package/dist/types/testUtil.d.ts.map +1 -0
- package/dist/types/testUtil.js +3 -0
- package/dist/types/testUtil.js.map +1 -0
- package/dist/utils.d.ts +67 -67
- package/dist/utils.js +226 -226
- package/package.json +39 -37
package/dist/pool.js
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.removeHook = exports.addHook = exports.createPool = void 0;
|
|
40
|
-
var pg_1 = require("pg");
|
|
41
|
-
var dictionary_1 = require("./dictionary");
|
|
42
|
-
var submit = pg_1.Query.prototype.submit;
|
|
43
|
-
pg_1.Query.prototype.submit = function () {
|
|
44
|
-
var _this = this;
|
|
45
|
-
onSendQueryHooks.forEach(function (hook) { return hook(_this.text, _this.values); });
|
|
46
|
-
submit.apply(this, arguments);
|
|
47
|
-
};
|
|
48
|
-
var onSendQueryHooks = [];
|
|
49
|
-
var addHook = function (_a) {
|
|
50
|
-
var event = _a.event, hook = _a.hook;
|
|
51
|
-
switch (event) {
|
|
52
|
-
case 'on-send-query':
|
|
53
|
-
onSendQueryHooks.push(hook);
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.addHook = addHook;
|
|
58
|
-
var removeHook = function (_a) {
|
|
59
|
-
var event = _a.event, hook = _a.hook;
|
|
60
|
-
switch (event) {
|
|
61
|
-
case 'on-send-query':
|
|
62
|
-
onSendQueryHooks.splice(onSendQueryHooks.indexOf(hook), 1);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
exports.removeHook = removeHook;
|
|
67
|
-
var createPool = function (connectionString) {
|
|
68
|
-
var pool = new pg_1.Pool({ connectionString: connectionString });
|
|
69
|
-
return {
|
|
70
|
-
$: pool,
|
|
71
|
-
transaction: function (callback, isolationLevel) {
|
|
72
|
-
if (isolationLevel === void 0) { isolationLevel = 'serializable'; }
|
|
73
|
-
return pool.connect().then(function (client) {
|
|
74
|
-
return client.query("BEGIN TRANSACTION ISOLATION LEVEL ".concat((0, dictionary_1.toTransactionIsolationLevel)(isolationLevel), " ;"))
|
|
75
|
-
.then(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
76
|
-
var result;
|
|
77
|
-
return __generator(this, function (_a) {
|
|
78
|
-
switch (_a.label) {
|
|
79
|
-
case 0: return [4 /*yield*/, callback(client)];
|
|
80
|
-
case 1:
|
|
81
|
-
result = _a.sent();
|
|
82
|
-
if (!result.ok) return [3 /*break*/, 3];
|
|
83
|
-
return [4 /*yield*/, client.query('COMMIT ;')];
|
|
84
|
-
case 2:
|
|
85
|
-
_a.sent();
|
|
86
|
-
return [3 /*break*/, 5];
|
|
87
|
-
case 3: return [4 /*yield*/, client.query('ROLLBACK ;')];
|
|
88
|
-
case 4:
|
|
89
|
-
_a.sent();
|
|
90
|
-
_a.label = 5;
|
|
91
|
-
case 5:
|
|
92
|
-
client.release();
|
|
93
|
-
return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}); })
|
|
97
|
-
.catch(function (err) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
-
var _1;
|
|
99
|
-
return __generator(this, function (_a) {
|
|
100
|
-
switch (_a.label) {
|
|
101
|
-
case 0:
|
|
102
|
-
_a.trys.push([0, 2, , 3]);
|
|
103
|
-
return [4 /*yield*/, client.query('ROLLBACK ;')];
|
|
104
|
-
case 1:
|
|
105
|
-
_a.sent();
|
|
106
|
-
return [3 /*break*/, 3];
|
|
107
|
-
case 2:
|
|
108
|
-
_1 = _a.sent();
|
|
109
|
-
return [3 /*break*/, 3];
|
|
110
|
-
case 3:
|
|
111
|
-
client.release();
|
|
112
|
-
throw err;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}); });
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
exports.createPool = createPool;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.removeHook = exports.addHook = exports.createPool = void 0;
|
|
40
|
+
var pg_1 = require("pg");
|
|
41
|
+
var dictionary_1 = require("./dictionary");
|
|
42
|
+
var submit = pg_1.Query.prototype.submit;
|
|
43
|
+
pg_1.Query.prototype.submit = function () {
|
|
44
|
+
var _this = this;
|
|
45
|
+
onSendQueryHooks.forEach(function (hook) { return hook(_this.text, _this.values); });
|
|
46
|
+
submit.apply(this, arguments);
|
|
47
|
+
};
|
|
48
|
+
var onSendQueryHooks = [];
|
|
49
|
+
var addHook = function (_a) {
|
|
50
|
+
var event = _a.event, hook = _a.hook;
|
|
51
|
+
switch (event) {
|
|
52
|
+
case 'on-send-query':
|
|
53
|
+
onSendQueryHooks.push(hook);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.addHook = addHook;
|
|
58
|
+
var removeHook = function (_a) {
|
|
59
|
+
var event = _a.event, hook = _a.hook;
|
|
60
|
+
switch (event) {
|
|
61
|
+
case 'on-send-query':
|
|
62
|
+
onSendQueryHooks.splice(onSendQueryHooks.indexOf(hook), 1);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.removeHook = removeHook;
|
|
67
|
+
var createPool = function (connectionString) {
|
|
68
|
+
var pool = new pg_1.Pool({ connectionString: connectionString });
|
|
69
|
+
return {
|
|
70
|
+
$: pool,
|
|
71
|
+
transaction: function (callback, isolationLevel) {
|
|
72
|
+
if (isolationLevel === void 0) { isolationLevel = 'serializable'; }
|
|
73
|
+
return pool.connect().then(function (client) {
|
|
74
|
+
return client.query("BEGIN TRANSACTION ISOLATION LEVEL ".concat((0, dictionary_1.toTransactionIsolationLevel)(isolationLevel), " ;"))
|
|
75
|
+
.then(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
76
|
+
var result;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0: return [4 /*yield*/, callback(client)];
|
|
80
|
+
case 1:
|
|
81
|
+
result = _a.sent();
|
|
82
|
+
if (!result.ok) return [3 /*break*/, 3];
|
|
83
|
+
return [4 /*yield*/, client.query('COMMIT ;')];
|
|
84
|
+
case 2:
|
|
85
|
+
_a.sent();
|
|
86
|
+
return [3 /*break*/, 5];
|
|
87
|
+
case 3: return [4 /*yield*/, client.query('ROLLBACK ;')];
|
|
88
|
+
case 4:
|
|
89
|
+
_a.sent();
|
|
90
|
+
_a.label = 5;
|
|
91
|
+
case 5:
|
|
92
|
+
client.release();
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}); })
|
|
97
|
+
.catch(function (err) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var _1;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
_a.trys.push([0, 2, , 3]);
|
|
103
|
+
return [4 /*yield*/, client.query('ROLLBACK ;')];
|
|
104
|
+
case 1:
|
|
105
|
+
_a.sent();
|
|
106
|
+
return [3 /*break*/, 3];
|
|
107
|
+
case 2:
|
|
108
|
+
_1 = _a.sent();
|
|
109
|
+
return [3 /*break*/, 3];
|
|
110
|
+
case 3:
|
|
111
|
+
client.release();
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}); });
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
exports.createPool = createPool;
|
|
121
121
|
//# sourceMappingURL=pool.js.map
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type { ClientBase } from 'pg';
|
|
2
|
-
import type Table from './types/table';
|
|
3
|
-
import { type Result } from 'never-catch';
|
|
4
|
-
declare const createTables: (client: ClientBase, tables: Table[], resolve?: boolean) => Promise<Result<undefined, string | {
|
|
5
|
-
db: unknown;
|
|
6
|
-
query: string;
|
|
7
|
-
}>>;
|
|
8
|
-
declare const dropTables: (client: ClientBase, tables: Table[], resolve?: boolean) => Promise<Result<undefined, string | {
|
|
9
|
-
db: unknown;
|
|
10
|
-
query: string;
|
|
11
|
-
}>>;
|
|
12
|
-
declare const resolveTablesDependency: (tables: Table[]) => Result<Table[], string>;
|
|
13
|
-
declare const getAllTablesAndDependencies: (tables: Table[]) => Result<[Table[], {
|
|
14
|
-
parent: Table;
|
|
15
|
-
child: Table;
|
|
16
|
-
}[]], string>;
|
|
17
|
-
declare const createSequencesSQL: (table: Table) => string[];
|
|
18
|
-
declare const dropSequencesSQL: (table: Table) => string[];
|
|
19
|
-
declare const createTableSQL: (table: Table) => string;
|
|
20
|
-
declare const dropTableSQL: (table: Table) => string;
|
|
21
|
-
declare const getSequenceName: (tableTitle: string, columnKey: string, column: {
|
|
22
|
-
title?: string;
|
|
23
|
-
seqTitle?: string;
|
|
24
|
-
}) => string;
|
|
25
|
-
export { createTables, dropTables, resolveTablesDependency, getAllTablesAndDependencies, createSequencesSQL, dropSequencesSQL, createTableSQL, dropTableSQL, getSequenceName };
|
|
1
|
+
import type { ClientBase } from 'pg';
|
|
2
|
+
import type Table from './types/table';
|
|
3
|
+
import { type Result } from 'never-catch';
|
|
4
|
+
declare const createTables: (client: ClientBase, tables: Table[], resolve?: boolean) => Promise<Result<undefined, string | {
|
|
5
|
+
db: unknown;
|
|
6
|
+
query: string;
|
|
7
|
+
}>>;
|
|
8
|
+
declare const dropTables: (client: ClientBase, tables: Table[], resolve?: boolean) => Promise<Result<undefined, string | {
|
|
9
|
+
db: unknown;
|
|
10
|
+
query: string;
|
|
11
|
+
}>>;
|
|
12
|
+
declare const resolveTablesDependency: (tables: Table[]) => Result<Table[], string>;
|
|
13
|
+
declare const getAllTablesAndDependencies: (tables: Table[]) => Result<[Table[], {
|
|
14
|
+
parent: Table;
|
|
15
|
+
child: Table;
|
|
16
|
+
}[]], string>;
|
|
17
|
+
declare const createSequencesSQL: (table: Table) => string[];
|
|
18
|
+
declare const dropSequencesSQL: (table: Table) => string[];
|
|
19
|
+
declare const createTableSQL: (table: Table) => string;
|
|
20
|
+
declare const dropTableSQL: (table: Table) => string;
|
|
21
|
+
declare const getSequenceName: (tableTitle: string, columnKey: string, column: {
|
|
22
|
+
title?: string;
|
|
23
|
+
seqTitle?: string;
|
|
24
|
+
}) => string;
|
|
25
|
+
export { createTables, dropTables, resolveTablesDependency, getAllTablesAndDependencies, createSequencesSQL, dropSequencesSQL, createTableSQL, dropTableSQL, getSequenceName };
|
|
26
26
|
//# sourceMappingURL=schema.d.ts.map
|