remult 0.22.7-exp.0 → 0.22.7
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/SseSubscriptionServer.d.ts +25 -25
- package/SseSubscriptionServer.js +145 -145
- package/ably.d.ts +13 -13
- package/ably.js +59 -59
- package/assign.d.ts +1 -1
- package/assign.js +9 -9
- package/classType.d.ts +3 -3
- package/classType.js +2 -2
- package/esm/SseSubscriptionServer.d.ts +25 -25
- package/esm/SseSubscriptionServer.js +107 -104
- package/esm/ably.d.ts +13 -13
- package/esm/ably.js +30 -28
- package/esm/assign.d.ts +1 -1
- package/esm/assign.js +5 -5
- package/esm/classType.d.ts +3 -3
- package/esm/classType.js +1 -1
- package/esm/graphql.d.ts +14 -14
- package/esm/graphql.js +785 -785
- package/esm/index.d.ts +31 -31
- package/esm/index.js +25 -25
- package/esm/inputTypes.d.ts +9 -9
- package/esm/inputTypes.js +9 -9
- package/esm/live-query/data-provider-live-query-storage.d.ts +23 -23
- package/esm/live-query/data-provider-live-query-storage.js +91 -93
- package/esm/myLog.d.ts +1 -1
- package/esm/myLog.js +5 -5
- package/esm/postgres/index.d.ts +2 -2
- package/esm/postgres/index.js +2 -2
- package/esm/postgres/postgres-data-provider.d.ts +36 -36
- package/esm/postgres/postgres-data-provider.js +126 -122
- package/esm/postgres/schema-builder.d.ts +19 -19
- package/esm/postgres/schema-builder.js +197 -196
- package/esm/remult-express.d.ts +9 -9
- package/esm/remult-express.js +26 -25
- package/esm/remult-fastify.d.ts +6 -6
- package/esm/remult-fastify.js +68 -68
- package/esm/remult-fresh.d.ts +17 -17
- package/esm/remult-fresh.js +26 -26
- package/esm/remult-knex/index.d.ts +30 -30
- package/esm/remult-knex/index.js +466 -460
- package/esm/remult-mongo.d.ts +24 -24
- package/esm/remult-mongo.js +269 -262
- package/esm/remult-next.d.ts +25 -25
- package/esm/remult-next.js +114 -114
- package/esm/remult-sveltekit.d.ts +4 -4
- package/esm/remult-sveltekit.js +71 -71
- package/esm/server/JsonEntityFileStorage.d.ts +11 -11
- package/esm/server/JsonEntityFileStorage.js +27 -26
- package/esm/server/core.d.ts +4 -4
- package/esm/server/core.js +4 -4
- package/esm/server/expressBridge.d.ts +128 -128
- package/esm/server/expressBridge.js +988 -971
- package/esm/server/index.d.ts +6 -6
- package/esm/server/index.js +12 -12
- package/esm/server/initAsyncHooks.d.ts +1 -1
- package/esm/server/initAsyncHooks.js +9 -9
- package/esm/server/initDataProvider.d.ts +2 -2
- package/esm/server/initDataProvider.js +14 -14
- package/esm/src/CompoundIdField.d.ts +27 -27
- package/esm/src/CompoundIdField.js +54 -41
- package/esm/src/__EntityValueProvider.d.ts +11 -11
- package/esm/src/__EntityValueProvider.js +1 -1
- package/esm/src/__RowsOfDataForTesting.d.ts +3 -3
- package/esm/src/__RowsOfDataForTesting.js +1 -1
- package/esm/src/buildRestDataProvider.d.ts +31 -31
- package/esm/src/buildRestDataProvider.js +121 -120
- package/esm/src/column-interfaces.d.ts +160 -160
- package/esm/src/column-interfaces.js +7 -7
- package/esm/src/column.d.ts +31 -31
- package/esm/src/column.js +108 -101
- package/esm/src/context.d.ts +134 -134
- package/esm/src/context.js +287 -282
- package/esm/src/data-api.d.ts +38 -38
- package/esm/src/data-api.js +281 -279
- package/esm/src/data-interfaces.d.ts +41 -41
- package/esm/src/data-interfaces.js +12 -12
- package/esm/src/data-providers/array-entity-data-provider.d.ts +22 -22
- package/esm/src/data-providers/array-entity-data-provider.js +252 -249
- package/esm/src/data-providers/in-memory-database.d.ts +9 -9
- package/esm/src/data-providers/in-memory-database.js +16 -18
- package/esm/src/data-providers/json-data-provider.d.ts +12 -12
- package/esm/src/data-providers/json-data-provider.js +55 -52
- package/esm/src/data-providers/rest-data-provider.d.ts +39 -39
- package/esm/src/data-providers/rest-data-provider.js +272 -267
- package/esm/src/data-providers/sql-database.d.ts +33 -33
- package/esm/src/data-providers/sql-database.js +401 -394
- package/esm/src/data-providers/web-sql-data-provider.d.ts +21 -21
- package/esm/src/data-providers/web-sql-data-provider.js +145 -137
- package/esm/src/entity.d.ts +95 -95
- package/esm/src/entity.js +1 -1
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +165 -162
- package/esm/src/filter/filter-interfaces.d.ts +86 -86
- package/esm/src/filter/filter-interfaces.js +524 -515
- package/esm/src/live-query/LiveQueryClient.d.ts +1 -1
- package/esm/src/live-query/LiveQueryClient.js +196 -192
- package/esm/src/live-query/SseSubscriptionClient.d.ts +5 -5
- package/esm/src/live-query/SseSubscriptionClient.js +86 -86
- package/esm/src/live-query/SubscriptionChannel.d.ts +41 -41
- package/esm/src/live-query/SubscriptionChannel.js +126 -121
- package/esm/src/live-query/SubscriptionServer.d.ts +38 -38
- package/esm/src/live-query/SubscriptionServer.js +114 -112
- package/esm/src/remult-proxy.d.ts +2 -2
- package/esm/src/remult-proxy.js +177 -178
- package/esm/src/remult3/DecoratorReplacer.d.ts +10 -10
- package/esm/src/remult3/DecoratorReplacer.js +20 -20
- package/esm/src/remult3/RepositoryImplementation.d.ts +332 -332
- package/esm/src/remult3/RepositoryImplementation.js +2122 -2051
- package/esm/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
- package/esm/src/remult3/__updateEntityBasedOnWhere.js +24 -24
- package/esm/src/remult3/entity.d.ts +28 -28
- package/esm/src/remult3/entity.js +70 -70
- package/esm/src/remult3/getEntityRef.d.ts +9 -9
- package/esm/src/remult3/getEntityRef.js +27 -27
- package/esm/src/remult3/remult3.d.ts +397 -397
- package/esm/src/remult3/remult3.js +1 -1
- package/esm/src/resultCompoundIdFilter.d.ts +3 -3
- package/esm/src/resultCompoundIdFilter.js +16 -16
- package/esm/src/server-action-info.d.ts +10 -10
- package/esm/src/server-action-info.js +12 -12
- package/esm/src/server-action.d.ts +79 -79
- package/esm/src/server-action.js +397 -387
- package/esm/src/sort.d.ts +16 -16
- package/esm/src/sort.js +105 -104
- package/esm/src/sql-command.d.ts +19 -19
- package/esm/src/sql-command.js +1 -1
- package/esm/src/validators.d.ts +14 -14
- package/esm/src/validators.js +36 -36
- package/esm/src/valueConverters.d.ts +13 -13
- package/esm/src/valueConverters.js +210 -210
- package/esm/urlBuilder.d.ts +6 -6
- package/esm/urlBuilder.js +20 -19
- package/graphql.d.ts +14 -14
- package/graphql.js +953 -953
- package/index.d.ts +31 -31
- package/index.js +67 -67
- package/inputTypes.d.ts +9 -9
- package/inputTypes.js +16 -16
- package/live-query/data-provider-live-query-storage.d.ts +23 -23
- package/live-query/data-provider-live-query-storage.js +263 -263
- package/myLog.d.ts +1 -1
- package/myLog.js +20 -20
- package/package.json +1 -1
- package/postgres/index.d.ts +2 -2
- package/postgres/index.js +5 -5
- package/postgres/postgres-data-provider.d.ts +36 -36
- package/postgres/postgres-data-provider.js +191 -191
- package/postgres/schema-builder.d.ts +19 -19
- package/postgres/schema-builder.js +369 -369
- package/remult-express.d.ts +9 -9
- package/remult-express.js +34 -33
- package/remult-fastify.d.ts +6 -6
- package/remult-fastify.js +79 -79
- package/remult-fresh.d.ts +17 -17
- package/remult-fresh.js +41 -41
- package/remult-knex/index.d.ts +30 -30
- package/remult-knex/index.js +917 -915
- package/remult-mongo.d.ts +24 -24
- package/remult-mongo.js +515 -515
- package/remult-next.d.ts +25 -25
- package/remult-next.js +171 -171
- package/remult-sveltekit.d.ts +4 -4
- package/remult-sveltekit.js +110 -110
- package/server/JsonEntityFileStorage.d.ts +11 -11
- package/server/JsonEntityFileStorage.js +35 -35
- package/server/core.d.ts +4 -4
- package/server/core.js +12 -12
- package/server/expressBridge.d.ts +128 -128
- package/server/expressBridge.js +1401 -1402
- package/server/index.d.ts +6 -6
- package/server/index.js +24 -24
- package/server/initAsyncHooks.d.ts +1 -1
- package/server/initAsyncHooks.js +13 -13
- package/server/initDataProvider.d.ts +2 -2
- package/server/initDataProvider.js +26 -26
- package/src/CompoundIdField.d.ts +27 -27
- package/src/CompoundIdField.js +54 -54
- package/src/__EntityValueProvider.d.ts +11 -11
- package/src/__EntityValueProvider.js +2 -2
- package/src/__RowsOfDataForTesting.d.ts +3 -3
- package/src/__RowsOfDataForTesting.js +2 -2
- package/src/buildRestDataProvider.d.ts +31 -31
- package/src/buildRestDataProvider.js +177 -174
- package/src/column-interfaces.d.ts +160 -160
- package/src/column-interfaces.js +11 -11
- package/src/column.d.ts +31 -31
- package/src/column.js +132 -132
- package/src/context.d.ts +134 -134
- package/src/context.js +451 -451
- package/src/data-api.d.ts +38 -38
- package/src/data-api.js +524 -524
- package/src/data-interfaces.d.ts +41 -41
- package/src/data-interfaces.js +16 -16
- package/src/data-providers/array-entity-data-provider.d.ts +22 -22
- package/src/data-providers/array-entity-data-provider.js +364 -364
- package/src/data-providers/in-memory-database.d.ts +9 -9
- package/src/data-providers/in-memory-database.js +33 -33
- package/src/data-providers/json-data-provider.d.ts +12 -12
- package/src/data-providers/json-data-provider.js +106 -106
- package/src/data-providers/rest-data-provider.d.ts +39 -39
- package/src/data-providers/rest-data-provider.js +388 -388
- package/src/data-providers/sql-database.d.ts +33 -33
- package/src/data-providers/sql-database.js +653 -653
- package/src/data-providers/web-sql-data-provider.d.ts +21 -21
- package/src/data-providers/web-sql-data-provider.js +229 -229
- package/src/entity.d.ts +95 -95
- package/src/entity.js +2 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
- package/src/filter/filter-consumer-bridge-to-sql-request.js +307 -307
- package/src/filter/filter-interfaces.d.ts +86 -86
- package/src/filter/filter-interfaces.js +693 -685
- package/src/live-query/LiveQueryClient.d.ts +1 -1
- package/src/live-query/LiveQueryClient.js +293 -293
- package/src/live-query/SseSubscriptionClient.d.ts +5 -5
- package/src/live-query/SseSubscriptionClient.js +154 -154
- package/src/live-query/SubscriptionChannel.d.ts +41 -41
- package/src/live-query/SubscriptionChannel.js +189 -189
- package/src/live-query/SubscriptionServer.d.ts +38 -38
- package/src/live-query/SubscriptionServer.js +264 -264
- package/src/remult-proxy.d.ts +2 -2
- package/src/remult-proxy.js +307 -307
- package/src/remult3/DecoratorReplacer.d.ts +10 -10
- package/src/remult3/DecoratorReplacer.js +24 -24
- package/src/remult3/RepositoryImplementation.d.ts +332 -332
- package/src/remult3/RepositoryImplementation.js +3391 -3373
- package/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
- package/src/remult3/__updateEntityBasedOnWhere.js +28 -28
- package/src/remult3/entity.d.ts +28 -28
- package/src/remult3/entity.js +88 -88
- package/src/remult3/getEntityRef.d.ts +9 -9
- package/src/remult3/getEntityRef.js +35 -35
- package/src/remult3/remult3.d.ts +397 -397
- package/src/remult3/remult3.js +2 -2
- package/src/resultCompoundIdFilter.d.ts +3 -3
- package/src/resultCompoundIdFilter.js +20 -20
- package/src/server-action-info.d.ts +10 -10
- package/src/server-action-info.js +15 -15
- package/src/server-action.d.ts +79 -79
- package/src/server-action.js +632 -632
- package/src/sort.d.ts +16 -16
- package/src/sort.js +161 -161
- package/src/sql-command.d.ts +19 -19
- package/src/sql-command.js +2 -2
- package/src/validators.d.ts +14 -14
- package/src/validators.js +71 -69
- package/src/valueConverters.d.ts +13 -13
- package/src/valueConverters.js +213 -213
- package/urlBuilder.d.ts +6 -6
- package/urlBuilder.js +25 -25
|
@@ -1,369 +1,369 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostgresSchemaBuilder = exports.verifyStructureOfAllEntities = exports.postgresColumnSyntax = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var context_1 = require("../src/context");
|
|
6
|
-
var filter_consumer_bridge_to_sql_request_1 = require("../src/filter/filter-consumer-bridge-to-sql-request");
|
|
7
|
-
var remult_proxy_1 = require("../src/remult-proxy");
|
|
8
|
-
var RepositoryImplementation_1 = require("../src/remult3/RepositoryImplementation");
|
|
9
|
-
var valueConverters_1 = require("../src/valueConverters");
|
|
10
|
-
function postgresColumnSyntax(x, dbName) {
|
|
11
|
-
var result = dbName;
|
|
12
|
-
if (x.valueType == Number) {
|
|
13
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
14
|
-
result += ' numeric' + (x.allowNull ? '' : ' default 0 not null');
|
|
15
|
-
else
|
|
16
|
-
result +=
|
|
17
|
-
' ' +
|
|
18
|
-
x.valueConverter.fieldTypeInDb +
|
|
19
|
-
(x.allowNull ? '' : ' default 0 not null');
|
|
20
|
-
}
|
|
21
|
-
else if (x.valueType == Date) {
|
|
22
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
23
|
-
if (x.valueConverter == valueConverters_1.ValueConverters.DateOnly)
|
|
24
|
-
result += ' date';
|
|
25
|
-
else
|
|
26
|
-
result += ' timestamp';
|
|
27
|
-
else
|
|
28
|
-
result += ' ' + x.valueConverter.fieldTypeInDb;
|
|
29
|
-
}
|
|
30
|
-
else if (x.valueType == Boolean)
|
|
31
|
-
result += ' boolean' + (x.allowNull ? '' : ' default false not null');
|
|
32
|
-
else if (x.valueConverter.fieldTypeInDb) {
|
|
33
|
-
result += ' ' + x.valueConverter.fieldTypeInDb;
|
|
34
|
-
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
35
|
-
result += ' default 0 not null';
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else
|
|
39
|
-
result += ' varchar' + (x.allowNull ? '' : " default '' not null");
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
exports.postgresColumnSyntax = postgresColumnSyntax;
|
|
43
|
-
function verifyStructureOfAllEntities(db, remult) {
|
|
44
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
45
|
-
return tslib_1.__generator(this, function (_a) {
|
|
46
|
-
switch (_a.label) {
|
|
47
|
-
case 0: return [4 /*yield*/, new PostgresSchemaBuilder(db).verifyStructureOfAllEntities(remult)];
|
|
48
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
exports.verifyStructureOfAllEntities = verifyStructureOfAllEntities;
|
|
54
|
-
var PostgresSchemaBuilder = /** @class */ (function () {
|
|
55
|
-
function PostgresSchemaBuilder(pool, schema) {
|
|
56
|
-
this.pool = pool;
|
|
57
|
-
this.specifiedSchema = '';
|
|
58
|
-
if (schema) {
|
|
59
|
-
this.specifiedSchema = schema;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
PostgresSchemaBuilder.prototype.removeQuotes = function (s) {
|
|
63
|
-
if (s.startsWith('"') && s.endsWith('"')) {
|
|
64
|
-
return s.substring(1, s.length - 1);
|
|
65
|
-
}
|
|
66
|
-
return s.toLocaleLowerCase();
|
|
67
|
-
};
|
|
68
|
-
PostgresSchemaBuilder.prototype.whereTableAndSchema = function (cmd, e) {
|
|
69
|
-
var table = '';
|
|
70
|
-
var schema = '';
|
|
71
|
-
if (this.specifiedSchema) {
|
|
72
|
-
schema = this.specifiedSchema;
|
|
73
|
-
}
|
|
74
|
-
var splited = e.$entityName.split('.');
|
|
75
|
-
// let's prioritize the specified schema at dbName level
|
|
76
|
-
if (splited.length > 1) {
|
|
77
|
-
schema = splited[0];
|
|
78
|
-
table = splited[1];
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
table = splited[0];
|
|
82
|
-
}
|
|
83
|
-
var where = [];
|
|
84
|
-
if (schema) {
|
|
85
|
-
where.push("table_schema="
|
|
86
|
-
}
|
|
87
|
-
where.push("table_name="
|
|
88
|
-
return where.join(' AND ');
|
|
89
|
-
};
|
|
90
|
-
PostgresSchemaBuilder.prototype.schemaAndName = function (e) {
|
|
91
|
-
if (e.$entityName.includes('.')) {
|
|
92
|
-
return e.$entityName;
|
|
93
|
-
}
|
|
94
|
-
if (this.specifiedSchema) {
|
|
95
|
-
return this.specifiedSchema
|
|
96
|
-
}
|
|
97
|
-
return e.$entityName;
|
|
98
|
-
};
|
|
99
|
-
PostgresSchemaBuilder.prototype.verifyStructureOfAllEntities = function (remult) {
|
|
100
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var completed, entities, _a, _b, entityClass, entity, e, e_1_1;
|
|
102
|
-
var e_1, _c;
|
|
103
|
-
return tslib_1.__generator(this, function (_d) {
|
|
104
|
-
switch (_d.label) {
|
|
105
|
-
case 0:
|
|
106
|
-
if (!remult) {
|
|
107
|
-
remult = remult_proxy_1.remult;
|
|
108
|
-
}
|
|
109
|
-
completed = new Set();
|
|
110
|
-
entities = [];
|
|
111
|
-
_d.label = 1;
|
|
112
|
-
case 1:
|
|
113
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
114
|
-
_a = tslib_1.__values(tslib_1.
|
|
115
|
-
_d.label = 2;
|
|
116
|
-
case 2:
|
|
117
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
118
|
-
entityClass = _b.value;
|
|
119
|
-
entity = remult.repo(entityClass).metadata;
|
|
120
|
-
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.dbNamesOf(entity)];
|
|
121
|
-
case 3:
|
|
122
|
-
e = _d.sent();
|
|
123
|
-
if (completed.has(e.$entityName))
|
|
124
|
-
return [3 /*break*/, 4];
|
|
125
|
-
completed.add(e.$entityName);
|
|
126
|
-
entities.push(entity);
|
|
127
|
-
_d.label = 4;
|
|
128
|
-
case 4:
|
|
129
|
-
_b = _a.next();
|
|
130
|
-
return [3 /*break*/, 2];
|
|
131
|
-
case 5: return [3 /*break*/, 8];
|
|
132
|
-
case 6:
|
|
133
|
-
e_1_1 = _d.sent();
|
|
134
|
-
e_1 = { error: e_1_1 };
|
|
135
|
-
return [3 /*break*/, 8];
|
|
136
|
-
case 7:
|
|
137
|
-
try {
|
|
138
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
139
|
-
}
|
|
140
|
-
finally { if (e_1) throw e_1.error; }
|
|
141
|
-
return [7 /*endfinally*/];
|
|
142
|
-
case 8: return [4 /*yield*/, this.ensureSchema(entities)];
|
|
143
|
-
case 9:
|
|
144
|
-
_d.sent();
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
PostgresSchemaBuilder.prototype.ensureSchema = function (entities) {
|
|
151
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var entities_1, entities_1_1, entity, e, err_1, e_2_1;
|
|
153
|
-
var e_2, _a;
|
|
154
|
-
return tslib_1.__generator(this, function (_b) {
|
|
155
|
-
switch (_b.label) {
|
|
156
|
-
case 0:
|
|
157
|
-
_b.trys.push([0, 10, 11, 12]);
|
|
158
|
-
entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next();
|
|
159
|
-
_b.label = 1;
|
|
160
|
-
case 1:
|
|
161
|
-
if (!!entities_1_1.done) return [3 /*break*/, 9];
|
|
162
|
-
entity = entities_1_1.value;
|
|
163
|
-
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.dbNamesOf(entity)];
|
|
164
|
-
case 2:
|
|
165
|
-
e = _b.sent();
|
|
166
|
-
_b.label = 3;
|
|
167
|
-
case 3:
|
|
168
|
-
_b.trys.push([3, 7, , 8]);
|
|
169
|
-
if (!!entity.options.sqlExpression) return [3 /*break*/, 6];
|
|
170
|
-
if (!(e.$entityName.toLowerCase().indexOf('from ') < 0)) return [3 /*break*/, 6];
|
|
171
|
-
return [4 /*yield*/, this.createIfNotExist(entity)];
|
|
172
|
-
case 4:
|
|
173
|
-
_b.sent();
|
|
174
|
-
return [4 /*yield*/, this.verifyAllColumns(entity)];
|
|
175
|
-
case 5:
|
|
176
|
-
_b.sent();
|
|
177
|
-
_b.label = 6;
|
|
178
|
-
case 6: return [3 /*break*/, 8];
|
|
179
|
-
case 7:
|
|
180
|
-
err_1 = _b.sent();
|
|
181
|
-
console.error('failed verify structure of ' + e.$entityName + ' ', err_1);
|
|
182
|
-
return [3 /*break*/, 8];
|
|
183
|
-
case 8:
|
|
184
|
-
entities_1_1 = entities_1.next();
|
|
185
|
-
return [3 /*break*/, 1];
|
|
186
|
-
case 9: return [3 /*break*/, 12];
|
|
187
|
-
case 10:
|
|
188
|
-
e_2_1 = _b.sent();
|
|
189
|
-
e_2 = { error: e_2_1 };
|
|
190
|
-
return [3 /*break*/, 12];
|
|
191
|
-
case 11:
|
|
192
|
-
try {
|
|
193
|
-
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
194
|
-
}
|
|
195
|
-
finally { if (e_2) throw e_2.error; }
|
|
196
|
-
return [7 /*endfinally*/];
|
|
197
|
-
case 12: return [2 /*return*/];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
PostgresSchemaBuilder.prototype.createIfNotExist = function (entity) {
|
|
203
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
204
|
-
var c, e;
|
|
205
|
-
var _this = this;
|
|
206
|
-
return tslib_1.__generator(this, function (_a) {
|
|
207
|
-
switch (_a.label) {
|
|
208
|
-
case 0:
|
|
209
|
-
c = this.pool.createCommand();
|
|
210
|
-
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.dbNamesOf(entity)];
|
|
211
|
-
case 1:
|
|
212
|
-
e = _a.sent();
|
|
213
|
-
return [4 /*yield*/, c
|
|
214
|
-
.execute("SELECT 1 FROM information_Schema.tables WHERE " +
|
|
215
|
-
|
|
216
|
-
.then(function (r) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
217
|
-
var result, _a, _b, x, sql;
|
|
218
|
-
var e_3, _c;
|
|
219
|
-
return tslib_1.__generator(this, function (_d) {
|
|
220
|
-
switch (_d.label) {
|
|
221
|
-
case 0:
|
|
222
|
-
if (!(r.rows.length == 0)) return [3 /*break*/, 2];
|
|
223
|
-
result = '';
|
|
224
|
-
try {
|
|
225
|
-
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
226
|
-
x = _b.value;
|
|
227
|
-
if (!filter_consumer_bridge_to_sql_request_1.isDbReadonly(x, e) || RepositoryImplementation_1.isAutoIncrement(x)) {
|
|
228
|
-
if (result.length != 0)
|
|
229
|
-
result += ',';
|
|
230
|
-
result += '\r\n ';
|
|
231
|
-
if (RepositoryImplementation_1.isAutoIncrement(x))
|
|
232
|
-
result += e.$dbNameOf(x) + ' serial';
|
|
233
|
-
else {
|
|
234
|
-
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
235
|
-
}
|
|
236
|
-
if (x == entity.idMetadata.field)
|
|
237
|
-
result += ' primary key';
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
242
|
-
finally {
|
|
243
|
-
try {
|
|
244
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
245
|
-
}
|
|
246
|
-
finally { if (e_3) throw e_3.error; }
|
|
247
|
-
}
|
|
248
|
-
sql = "CREATE table "
|
|
249
|
-
if (PostgresSchemaBuilder.logToConsole)
|
|
250
|
-
console.info(sql);
|
|
251
|
-
return [4 /*yield*/, this.pool.execute(sql)];
|
|
252
|
-
case 1:
|
|
253
|
-
_d.sent();
|
|
254
|
-
_d.label = 2;
|
|
255
|
-
case 2: return [2 /*return*/];
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}); })];
|
|
259
|
-
case 2:
|
|
260
|
-
_a.sent();
|
|
261
|
-
return [2 /*return*/];
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
PostgresSchemaBuilder.prototype.addColumnIfNotExist = function (entity, c) {
|
|
267
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
268
|
-
var e, cmd, colName, sql, err_2;
|
|
269
|
-
return tslib_1.__generator(this, function (_a) {
|
|
270
|
-
switch (_a.label) {
|
|
271
|
-
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.dbNamesOf(entity)];
|
|
272
|
-
case 1:
|
|
273
|
-
e = _a.sent();
|
|
274
|
-
if (filter_consumer_bridge_to_sql_request_1.isDbReadonly(c(entity), e))
|
|
275
|
-
return [2 /*return*/];
|
|
276
|
-
_a.label = 2;
|
|
277
|
-
case 2:
|
|
278
|
-
_a.trys.push([2, 6, , 7]);
|
|
279
|
-
cmd = this.pool.createCommand();
|
|
280
|
-
colName = e.$dbNameOf(c(entity));
|
|
281
|
-
return [4 /*yield*/, cmd.execute("SELECT 1 FROM information_schema.columns WHERE " +
|
|
282
|
-
(this.whereTableAndSchema(cmd, e)
|
|
283
|
-
|
|
284
|
-
case 3:
|
|
285
|
-
if (!((_a.sent()).rows.length == 0)) return [3 /*break*/, 5];
|
|
286
|
-
sql = "ALTER table "
|
|
287
|
-
|
|
288
|
-
if (PostgresSchemaBuilder.logToConsole)
|
|
289
|
-
console.info(sql);
|
|
290
|
-
return [4 /*yield*/, this.pool.execute(sql)];
|
|
291
|
-
case 4:
|
|
292
|
-
_a.sent();
|
|
293
|
-
_a.label = 5;
|
|
294
|
-
case 5: return [3 /*break*/, 7];
|
|
295
|
-
case 6:
|
|
296
|
-
err_2 = _a.sent();
|
|
297
|
-
console.error(err_2);
|
|
298
|
-
return [3 /*break*/, 7];
|
|
299
|
-
case 7: return [2 /*return*/];
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
};
|
|
304
|
-
PostgresSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
305
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var cmd, e, cols, _a, _b, col, colName, sql, e_4_1, err_3;
|
|
307
|
-
var e_4, _c;
|
|
308
|
-
return tslib_1.__generator(this, function (_d) {
|
|
309
|
-
switch (_d.label) {
|
|
310
|
-
case 0:
|
|
311
|
-
_d.trys.push([0, 11, , 12]);
|
|
312
|
-
cmd = this.pool.createCommand();
|
|
313
|
-
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.dbNamesOf(entity)];
|
|
314
|
-
case 1:
|
|
315
|
-
e = _d.sent();
|
|
316
|
-
return [4 /*yield*/, cmd.execute("SELECT column_name FROM information_schema.columns WHERE " +
|
|
317
|
-
|
|
318
|
-
case 2:
|
|
319
|
-
cols = (_d.sent()).rows.map(function (x) { return x.column_name.toLocaleLowerCase(); });
|
|
320
|
-
_d.label = 3;
|
|
321
|
-
case 3:
|
|
322
|
-
_d.trys.push([3, 8, 9, 10]);
|
|
323
|
-
_a = tslib_1.__values(entity.fields), _b = _a.next();
|
|
324
|
-
_d.label = 4;
|
|
325
|
-
case 4:
|
|
326
|
-
if (!!_b.done) return [3 /*break*/, 7];
|
|
327
|
-
col = _b.value;
|
|
328
|
-
if (!!filter_consumer_bridge_to_sql_request_1.isDbReadonly(col, e)) return [3 /*break*/, 6];
|
|
329
|
-
colName = e.$dbNameOf(col).toLocaleLowerCase();
|
|
330
|
-
if (colName.startsWith('"') && colName.endsWith('"'))
|
|
331
|
-
colName = colName.substring(1, colName.length - 1);
|
|
332
|
-
if (!!cols.includes(colName)) return [3 /*break*/, 6];
|
|
333
|
-
sql = "ALTER table "
|
|
334
|
-
|
|
335
|
-
if (PostgresSchemaBuilder.logToConsole)
|
|
336
|
-
console.info(sql);
|
|
337
|
-
return [4 /*yield*/, this.pool.execute(sql)];
|
|
338
|
-
case 5:
|
|
339
|
-
_d.sent();
|
|
340
|
-
_d.label = 6;
|
|
341
|
-
case 6:
|
|
342
|
-
_b = _a.next();
|
|
343
|
-
return [3 /*break*/, 4];
|
|
344
|
-
case 7: return [3 /*break*/, 10];
|
|
345
|
-
case 8:
|
|
346
|
-
e_4_1 = _d.sent();
|
|
347
|
-
e_4 = { error: e_4_1 };
|
|
348
|
-
return [3 /*break*/, 10];
|
|
349
|
-
case 9:
|
|
350
|
-
try {
|
|
351
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
352
|
-
}
|
|
353
|
-
finally { if (e_4) throw e_4.error; }
|
|
354
|
-
return [7 /*endfinally*/];
|
|
355
|
-
case 10: return [3 /*break*/, 12];
|
|
356
|
-
case 11:
|
|
357
|
-
err_3 = _d.sent();
|
|
358
|
-
console.error(err_3);
|
|
359
|
-
return [3 /*break*/, 12];
|
|
360
|
-
case 12: return [2 /*return*/];
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
};
|
|
365
|
-
//@internal
|
|
366
|
-
PostgresSchemaBuilder.logToConsole = true;
|
|
367
|
-
return PostgresSchemaBuilder;
|
|
368
|
-
}());
|
|
369
|
-
exports.PostgresSchemaBuilder = PostgresSchemaBuilder;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresSchemaBuilder = exports.verifyStructureOfAllEntities = exports.postgresColumnSyntax = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var context_1 = require("../src/context");
|
|
6
|
+
var filter_consumer_bridge_to_sql_request_1 = require("../src/filter/filter-consumer-bridge-to-sql-request");
|
|
7
|
+
var remult_proxy_1 = require("../src/remult-proxy");
|
|
8
|
+
var RepositoryImplementation_1 = require("../src/remult3/RepositoryImplementation");
|
|
9
|
+
var valueConverters_1 = require("../src/valueConverters");
|
|
10
|
+
function postgresColumnSyntax(x, dbName) {
|
|
11
|
+
var result = dbName;
|
|
12
|
+
if (x.valueType == Number) {
|
|
13
|
+
if (!x.valueConverter.fieldTypeInDb)
|
|
14
|
+
result += ' numeric' + (x.allowNull ? '' : ' default 0 not null');
|
|
15
|
+
else
|
|
16
|
+
result +=
|
|
17
|
+
' ' +
|
|
18
|
+
x.valueConverter.fieldTypeInDb +
|
|
19
|
+
(x.allowNull ? '' : ' default 0 not null');
|
|
20
|
+
}
|
|
21
|
+
else if (x.valueType == Date) {
|
|
22
|
+
if (!x.valueConverter.fieldTypeInDb)
|
|
23
|
+
if (x.valueConverter == valueConverters_1.ValueConverters.DateOnly)
|
|
24
|
+
result += ' date';
|
|
25
|
+
else
|
|
26
|
+
result += ' timestamp';
|
|
27
|
+
else
|
|
28
|
+
result += ' ' + x.valueConverter.fieldTypeInDb;
|
|
29
|
+
}
|
|
30
|
+
else if (x.valueType == Boolean)
|
|
31
|
+
result += ' boolean' + (x.allowNull ? '' : ' default false not null');
|
|
32
|
+
else if (x.valueConverter.fieldTypeInDb) {
|
|
33
|
+
result += ' ' + x.valueConverter.fieldTypeInDb;
|
|
34
|
+
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
35
|
+
result += ' default 0 not null';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
result += ' varchar' + (x.allowNull ? '' : " default '' not null");
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
exports.postgresColumnSyntax = postgresColumnSyntax;
|
|
43
|
+
function verifyStructureOfAllEntities(db, remult) {
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
45
|
+
return tslib_1.__generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0: return [4 /*yield*/, new PostgresSchemaBuilder(db).verifyStructureOfAllEntities(remult)];
|
|
48
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.verifyStructureOfAllEntities = verifyStructureOfAllEntities;
|
|
54
|
+
var PostgresSchemaBuilder = /** @class */ (function () {
|
|
55
|
+
function PostgresSchemaBuilder(pool, schema) {
|
|
56
|
+
this.pool = pool;
|
|
57
|
+
this.specifiedSchema = '';
|
|
58
|
+
if (schema) {
|
|
59
|
+
this.specifiedSchema = schema;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
PostgresSchemaBuilder.prototype.removeQuotes = function (s) {
|
|
63
|
+
if (s.startsWith('"') && s.endsWith('"')) {
|
|
64
|
+
return s.substring(1, s.length - 1);
|
|
65
|
+
}
|
|
66
|
+
return s.toLocaleLowerCase();
|
|
67
|
+
};
|
|
68
|
+
PostgresSchemaBuilder.prototype.whereTableAndSchema = function (cmd, e) {
|
|
69
|
+
var table = '';
|
|
70
|
+
var schema = '';
|
|
71
|
+
if (this.specifiedSchema) {
|
|
72
|
+
schema = this.specifiedSchema;
|
|
73
|
+
}
|
|
74
|
+
var splited = e.$entityName.split('.');
|
|
75
|
+
// let's prioritize the specified schema at dbName level
|
|
76
|
+
if (splited.length > 1) {
|
|
77
|
+
schema = splited[0];
|
|
78
|
+
table = splited[1];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
table = splited[0];
|
|
82
|
+
}
|
|
83
|
+
var where = [];
|
|
84
|
+
if (schema) {
|
|
85
|
+
where.push("table_schema=".concat(cmd.addParameterAndReturnSqlToken(this.removeQuotes(schema))));
|
|
86
|
+
}
|
|
87
|
+
where.push("table_name=".concat(cmd.addParameterAndReturnSqlToken(this.removeQuotes(table))));
|
|
88
|
+
return where.join(' AND ');
|
|
89
|
+
};
|
|
90
|
+
PostgresSchemaBuilder.prototype.schemaAndName = function (e) {
|
|
91
|
+
if (e.$entityName.includes('.')) {
|
|
92
|
+
return e.$entityName;
|
|
93
|
+
}
|
|
94
|
+
if (this.specifiedSchema) {
|
|
95
|
+
return "".concat(this.specifiedSchema, ".").concat(e.$entityName);
|
|
96
|
+
}
|
|
97
|
+
return e.$entityName;
|
|
98
|
+
};
|
|
99
|
+
PostgresSchemaBuilder.prototype.verifyStructureOfAllEntities = function (remult) {
|
|
100
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var completed, entities, _a, _b, entityClass, entity, e, e_1_1;
|
|
102
|
+
var e_1, _c;
|
|
103
|
+
return tslib_1.__generator(this, function (_d) {
|
|
104
|
+
switch (_d.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
if (!remult) {
|
|
107
|
+
remult = remult_proxy_1.remult;
|
|
108
|
+
}
|
|
109
|
+
completed = new Set();
|
|
110
|
+
entities = [];
|
|
111
|
+
_d.label = 1;
|
|
112
|
+
case 1:
|
|
113
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
114
|
+
_a = tslib_1.__values(tslib_1.__spreadArray([], tslib_1.__read(context_1.allEntities), false).reverse()), _b = _a.next();
|
|
115
|
+
_d.label = 2;
|
|
116
|
+
case 2:
|
|
117
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
118
|
+
entityClass = _b.value;
|
|
119
|
+
entity = remult.repo(entityClass).metadata;
|
|
120
|
+
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_1.dbNamesOf)(entity)];
|
|
121
|
+
case 3:
|
|
122
|
+
e = _d.sent();
|
|
123
|
+
if (completed.has(e.$entityName))
|
|
124
|
+
return [3 /*break*/, 4];
|
|
125
|
+
completed.add(e.$entityName);
|
|
126
|
+
entities.push(entity);
|
|
127
|
+
_d.label = 4;
|
|
128
|
+
case 4:
|
|
129
|
+
_b = _a.next();
|
|
130
|
+
return [3 /*break*/, 2];
|
|
131
|
+
case 5: return [3 /*break*/, 8];
|
|
132
|
+
case 6:
|
|
133
|
+
e_1_1 = _d.sent();
|
|
134
|
+
e_1 = { error: e_1_1 };
|
|
135
|
+
return [3 /*break*/, 8];
|
|
136
|
+
case 7:
|
|
137
|
+
try {
|
|
138
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
139
|
+
}
|
|
140
|
+
finally { if (e_1) throw e_1.error; }
|
|
141
|
+
return [7 /*endfinally*/];
|
|
142
|
+
case 8: return [4 /*yield*/, this.ensureSchema(entities)];
|
|
143
|
+
case 9:
|
|
144
|
+
_d.sent();
|
|
145
|
+
return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
PostgresSchemaBuilder.prototype.ensureSchema = function (entities) {
|
|
151
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var entities_1, entities_1_1, entity, e, err_1, e_2_1;
|
|
153
|
+
var e_2, _a;
|
|
154
|
+
return tslib_1.__generator(this, function (_b) {
|
|
155
|
+
switch (_b.label) {
|
|
156
|
+
case 0:
|
|
157
|
+
_b.trys.push([0, 10, 11, 12]);
|
|
158
|
+
entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next();
|
|
159
|
+
_b.label = 1;
|
|
160
|
+
case 1:
|
|
161
|
+
if (!!entities_1_1.done) return [3 /*break*/, 9];
|
|
162
|
+
entity = entities_1_1.value;
|
|
163
|
+
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_1.dbNamesOf)(entity)];
|
|
164
|
+
case 2:
|
|
165
|
+
e = _b.sent();
|
|
166
|
+
_b.label = 3;
|
|
167
|
+
case 3:
|
|
168
|
+
_b.trys.push([3, 7, , 8]);
|
|
169
|
+
if (!!entity.options.sqlExpression) return [3 /*break*/, 6];
|
|
170
|
+
if (!(e.$entityName.toLowerCase().indexOf('from ') < 0)) return [3 /*break*/, 6];
|
|
171
|
+
return [4 /*yield*/, this.createIfNotExist(entity)];
|
|
172
|
+
case 4:
|
|
173
|
+
_b.sent();
|
|
174
|
+
return [4 /*yield*/, this.verifyAllColumns(entity)];
|
|
175
|
+
case 5:
|
|
176
|
+
_b.sent();
|
|
177
|
+
_b.label = 6;
|
|
178
|
+
case 6: return [3 /*break*/, 8];
|
|
179
|
+
case 7:
|
|
180
|
+
err_1 = _b.sent();
|
|
181
|
+
console.error('failed verify structure of ' + e.$entityName + ' ', err_1);
|
|
182
|
+
return [3 /*break*/, 8];
|
|
183
|
+
case 8:
|
|
184
|
+
entities_1_1 = entities_1.next();
|
|
185
|
+
return [3 /*break*/, 1];
|
|
186
|
+
case 9: return [3 /*break*/, 12];
|
|
187
|
+
case 10:
|
|
188
|
+
e_2_1 = _b.sent();
|
|
189
|
+
e_2 = { error: e_2_1 };
|
|
190
|
+
return [3 /*break*/, 12];
|
|
191
|
+
case 11:
|
|
192
|
+
try {
|
|
193
|
+
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
194
|
+
}
|
|
195
|
+
finally { if (e_2) throw e_2.error; }
|
|
196
|
+
return [7 /*endfinally*/];
|
|
197
|
+
case 12: return [2 /*return*/];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
PostgresSchemaBuilder.prototype.createIfNotExist = function (entity) {
|
|
203
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
204
|
+
var c, e;
|
|
205
|
+
var _this = this;
|
|
206
|
+
return tslib_1.__generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
c = this.pool.createCommand();
|
|
210
|
+
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_1.dbNamesOf)(entity)];
|
|
211
|
+
case 1:
|
|
212
|
+
e = _a.sent();
|
|
213
|
+
return [4 /*yield*/, c
|
|
214
|
+
.execute("SELECT 1 FROM information_Schema.tables WHERE " +
|
|
215
|
+
"".concat(this.whereTableAndSchema(c, e)))
|
|
216
|
+
.then(function (r) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
217
|
+
var result, _a, _b, x, sql;
|
|
218
|
+
var e_3, _c;
|
|
219
|
+
return tslib_1.__generator(this, function (_d) {
|
|
220
|
+
switch (_d.label) {
|
|
221
|
+
case 0:
|
|
222
|
+
if (!(r.rows.length == 0)) return [3 /*break*/, 2];
|
|
223
|
+
result = '';
|
|
224
|
+
try {
|
|
225
|
+
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
226
|
+
x = _b.value;
|
|
227
|
+
if (!(0, filter_consumer_bridge_to_sql_request_1.isDbReadonly)(x, e) || (0, RepositoryImplementation_1.isAutoIncrement)(x)) {
|
|
228
|
+
if (result.length != 0)
|
|
229
|
+
result += ',';
|
|
230
|
+
result += '\r\n ';
|
|
231
|
+
if ((0, RepositoryImplementation_1.isAutoIncrement)(x))
|
|
232
|
+
result += e.$dbNameOf(x) + ' serial';
|
|
233
|
+
else {
|
|
234
|
+
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
235
|
+
}
|
|
236
|
+
if (x == entity.idMetadata.field)
|
|
237
|
+
result += ' primary key';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
242
|
+
finally {
|
|
243
|
+
try {
|
|
244
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
245
|
+
}
|
|
246
|
+
finally { if (e_3) throw e_3.error; }
|
|
247
|
+
}
|
|
248
|
+
sql = "CREATE table ".concat(this.schemaAndName(e), " (").concat(result, "\r\n)");
|
|
249
|
+
if (PostgresSchemaBuilder.logToConsole)
|
|
250
|
+
console.info(sql);
|
|
251
|
+
return [4 /*yield*/, this.pool.execute(sql)];
|
|
252
|
+
case 1:
|
|
253
|
+
_d.sent();
|
|
254
|
+
_d.label = 2;
|
|
255
|
+
case 2: return [2 /*return*/];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}); })];
|
|
259
|
+
case 2:
|
|
260
|
+
_a.sent();
|
|
261
|
+
return [2 /*return*/];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
PostgresSchemaBuilder.prototype.addColumnIfNotExist = function (entity, c) {
|
|
267
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
268
|
+
var e, cmd, colName, sql, err_2;
|
|
269
|
+
return tslib_1.__generator(this, function (_a) {
|
|
270
|
+
switch (_a.label) {
|
|
271
|
+
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_1.dbNamesOf)(entity)];
|
|
272
|
+
case 1:
|
|
273
|
+
e = _a.sent();
|
|
274
|
+
if ((0, filter_consumer_bridge_to_sql_request_1.isDbReadonly)(c(entity), e))
|
|
275
|
+
return [2 /*return*/];
|
|
276
|
+
_a.label = 2;
|
|
277
|
+
case 2:
|
|
278
|
+
_a.trys.push([2, 6, , 7]);
|
|
279
|
+
cmd = this.pool.createCommand();
|
|
280
|
+
colName = e.$dbNameOf(c(entity));
|
|
281
|
+
return [4 /*yield*/, cmd.execute("SELECT 1 FROM information_schema.columns WHERE " +
|
|
282
|
+
"".concat(this.whereTableAndSchema(cmd, e), " ") +
|
|
283
|
+
"AND column_name=".concat(cmd.addParameterAndReturnSqlToken(colName.toLocaleLowerCase())))];
|
|
284
|
+
case 3:
|
|
285
|
+
if (!((_a.sent()).rows.length == 0)) return [3 /*break*/, 5];
|
|
286
|
+
sql = "ALTER table ".concat(this.schemaAndName(e), " ") +
|
|
287
|
+
"ADD column ".concat(postgresColumnSyntax(c(entity), colName));
|
|
288
|
+
if (PostgresSchemaBuilder.logToConsole)
|
|
289
|
+
console.info(sql);
|
|
290
|
+
return [4 /*yield*/, this.pool.execute(sql)];
|
|
291
|
+
case 4:
|
|
292
|
+
_a.sent();
|
|
293
|
+
_a.label = 5;
|
|
294
|
+
case 5: return [3 /*break*/, 7];
|
|
295
|
+
case 6:
|
|
296
|
+
err_2 = _a.sent();
|
|
297
|
+
console.error(err_2);
|
|
298
|
+
return [3 /*break*/, 7];
|
|
299
|
+
case 7: return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
PostgresSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
305
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
306
|
+
var cmd, e, cols, _a, _b, col, colName, sql, e_4_1, err_3;
|
|
307
|
+
var e_4, _c;
|
|
308
|
+
return tslib_1.__generator(this, function (_d) {
|
|
309
|
+
switch (_d.label) {
|
|
310
|
+
case 0:
|
|
311
|
+
_d.trys.push([0, 11, , 12]);
|
|
312
|
+
cmd = this.pool.createCommand();
|
|
313
|
+
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_1.dbNamesOf)(entity)];
|
|
314
|
+
case 1:
|
|
315
|
+
e = _d.sent();
|
|
316
|
+
return [4 /*yield*/, cmd.execute("SELECT column_name FROM information_schema.columns WHERE " +
|
|
317
|
+
"".concat(this.whereTableAndSchema(cmd, e)))];
|
|
318
|
+
case 2:
|
|
319
|
+
cols = (_d.sent()).rows.map(function (x) { return x.column_name.toLocaleLowerCase(); });
|
|
320
|
+
_d.label = 3;
|
|
321
|
+
case 3:
|
|
322
|
+
_d.trys.push([3, 8, 9, 10]);
|
|
323
|
+
_a = tslib_1.__values(entity.fields), _b = _a.next();
|
|
324
|
+
_d.label = 4;
|
|
325
|
+
case 4:
|
|
326
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
327
|
+
col = _b.value;
|
|
328
|
+
if (!!(0, filter_consumer_bridge_to_sql_request_1.isDbReadonly)(col, e)) return [3 /*break*/, 6];
|
|
329
|
+
colName = e.$dbNameOf(col).toLocaleLowerCase();
|
|
330
|
+
if (colName.startsWith('"') && colName.endsWith('"'))
|
|
331
|
+
colName = colName.substring(1, colName.length - 1);
|
|
332
|
+
if (!!cols.includes(colName)) return [3 /*break*/, 6];
|
|
333
|
+
sql = "ALTER table ".concat(this.schemaAndName(e), " ") +
|
|
334
|
+
"add column ".concat(postgresColumnSyntax(col, e.$dbNameOf(col)));
|
|
335
|
+
if (PostgresSchemaBuilder.logToConsole)
|
|
336
|
+
console.info(sql);
|
|
337
|
+
return [4 /*yield*/, this.pool.execute(sql)];
|
|
338
|
+
case 5:
|
|
339
|
+
_d.sent();
|
|
340
|
+
_d.label = 6;
|
|
341
|
+
case 6:
|
|
342
|
+
_b = _a.next();
|
|
343
|
+
return [3 /*break*/, 4];
|
|
344
|
+
case 7: return [3 /*break*/, 10];
|
|
345
|
+
case 8:
|
|
346
|
+
e_4_1 = _d.sent();
|
|
347
|
+
e_4 = { error: e_4_1 };
|
|
348
|
+
return [3 /*break*/, 10];
|
|
349
|
+
case 9:
|
|
350
|
+
try {
|
|
351
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
352
|
+
}
|
|
353
|
+
finally { if (e_4) throw e_4.error; }
|
|
354
|
+
return [7 /*endfinally*/];
|
|
355
|
+
case 10: return [3 /*break*/, 12];
|
|
356
|
+
case 11:
|
|
357
|
+
err_3 = _d.sent();
|
|
358
|
+
console.error(err_3);
|
|
359
|
+
return [3 /*break*/, 12];
|
|
360
|
+
case 12: return [2 /*return*/];
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
//@internal
|
|
366
|
+
PostgresSchemaBuilder.logToConsole = true;
|
|
367
|
+
return PostgresSchemaBuilder;
|
|
368
|
+
}());
|
|
369
|
+
exports.PostgresSchemaBuilder = PostgresSchemaBuilder;
|