remult 0.27.11 → 0.27.12
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/esm/index.js +0 -1
- package/esm/live-query/data-provider-live-query-storage.js +0 -2
- package/esm/postgres/schema-builder.js +0 -41
- package/esm/remult-duckdb.js +7 -12
- package/esm/remult-knex/index.js +0 -7
- package/esm/remult-mongo.js +33 -0
- package/esm/remult-sqlite-core.js +33 -5
- package/esm/server/get-remult-admin-html.js +1 -1
- package/esm/server/remult-api-server.js +3 -4
- package/esm/src/data-providers/array-entity-data-provider.js +26 -11
- package/esm/src/data-providers/in-memory-database.js +1 -1
- package/esm/src/filter/filter-interfaces.js +1 -0
- package/esm/src/remult3/RepositoryImplementation.js +7 -3
- package/esm/src/remult3/remult3.js +0 -3
- package/index.d.ts +0 -1
- package/index.js +1 -3
- package/live-query/data-provider-live-query-storage.js +0 -2
- package/package.json +1 -1
- package/postgres/schema-builder.d.ts +0 -4
- package/postgres/schema-builder.js +15 -118
- package/remult-duckdb.d.ts +1 -1
- package/remult-duckdb.js +7 -12
- package/remult-knex/index.d.ts +0 -2
- package/remult-knex/index.js +0 -18
- package/remult-mongo.d.ts +2 -1
- package/remult-mongo.js +128 -37
- package/remult-sqlite-core.d.ts +2 -1
- package/remult-sqlite-core.js +116 -29
- package/server/get-remult-admin-html.js +1 -1
- package/server/remult-api-server.js +7 -7
- package/src/data-providers/array-entity-data-provider.js +82 -37
- package/src/data-providers/in-memory-database.js +1 -1
- package/src/entity.d.ts +4 -4
- package/src/filter/filter-interfaces.js +1 -0
- package/src/remult3/RepositoryImplementation.js +7 -3
- package/src/remult3/remult3.d.ts +17 -2
- package/src/remult3/remult3.js +0 -3
- package/esm/src/data-providers/web-sql-data-provider.js +0 -140
- package/src/data-providers/web-sql-data-provider.d.ts +0 -20
- package/src/data-providers/web-sql-data-provider.js +0 -228
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebSqlDataProvider = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var filter_consumer_bridge_to_sql_request_js_1 = require("../filter/filter-consumer-bridge-to-sql-request.js");
|
|
6
|
-
var RepositoryImplementation_js_1 = require("../remult3/RepositoryImplementation.js");
|
|
7
|
-
var sql_database_js_1 = require("./sql-database.js");
|
|
8
|
-
//SqlDatabase.LogToConsole = true;
|
|
9
|
-
var WebSqlDataProvider = /** @class */ (function () {
|
|
10
|
-
function WebSqlDataProvider(databaseName, databaseSize) {
|
|
11
|
-
if (databaseSize === void 0) { databaseSize = 2 * 1024 * 1024; }
|
|
12
|
-
this.databaseName = databaseName;
|
|
13
|
-
//@ts-ignore
|
|
14
|
-
this.db = window.openDatabase(databaseName, '1.0', databaseName, databaseSize);
|
|
15
|
-
}
|
|
16
|
-
WebSqlDataProvider.prototype.end = function () {
|
|
17
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
18
|
-
return [2 /*return*/];
|
|
19
|
-
}); });
|
|
20
|
-
};
|
|
21
|
-
WebSqlDataProvider.prototype.getLimitSqlSyntax = function (limit, offset) {
|
|
22
|
-
return ' limit ' + limit + ' offset ' + offset;
|
|
23
|
-
};
|
|
24
|
-
WebSqlDataProvider.prototype.entityIsUsedForTheFirstTime = function (entity) {
|
|
25
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
26
|
-
return tslib_1.__generator(this, function (_a) {
|
|
27
|
-
switch (_a.label) {
|
|
28
|
-
case 0: return [4 /*yield*/, this.createTable(entity)];
|
|
29
|
-
case 1:
|
|
30
|
-
_a.sent();
|
|
31
|
-
return [2 /*return*/];
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
WebSqlDataProvider.prototype.ensureSchema = function (entities) {
|
|
37
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
38
|
-
var entities_1, entities_1_1, entity, e_1_1;
|
|
39
|
-
var e_1, _a;
|
|
40
|
-
return tslib_1.__generator(this, function (_b) {
|
|
41
|
-
switch (_b.label) {
|
|
42
|
-
case 0:
|
|
43
|
-
_b.trys.push([0, 5, 6, 7]);
|
|
44
|
-
entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next();
|
|
45
|
-
_b.label = 1;
|
|
46
|
-
case 1:
|
|
47
|
-
if (!!entities_1_1.done) return [3 /*break*/, 4];
|
|
48
|
-
entity = entities_1_1.value;
|
|
49
|
-
return [4 /*yield*/, this.createTable(entity)];
|
|
50
|
-
case 2:
|
|
51
|
-
_b.sent();
|
|
52
|
-
_b.label = 3;
|
|
53
|
-
case 3:
|
|
54
|
-
entities_1_1 = entities_1.next();
|
|
55
|
-
return [3 /*break*/, 1];
|
|
56
|
-
case 4: return [3 /*break*/, 7];
|
|
57
|
-
case 5:
|
|
58
|
-
e_1_1 = _b.sent();
|
|
59
|
-
e_1 = { error: e_1_1 };
|
|
60
|
-
return [3 /*break*/, 7];
|
|
61
|
-
case 6:
|
|
62
|
-
try {
|
|
63
|
-
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
64
|
-
}
|
|
65
|
-
finally { if (e_1) throw e_1.error; }
|
|
66
|
-
return [7 /*endfinally*/];
|
|
67
|
-
case 7: return [2 /*return*/];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
WebSqlDataProvider.prototype.dropTable = function (entity) {
|
|
73
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
74
|
-
var e, sql;
|
|
75
|
-
return tslib_1.__generator(this, function (_a) {
|
|
76
|
-
switch (_a.label) {
|
|
77
|
-
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOf)(entity)];
|
|
78
|
-
case 1:
|
|
79
|
-
e = _a.sent();
|
|
80
|
-
sql = 'drop table if exists ' + e.$entityName;
|
|
81
|
-
if (sql_database_js_1.SqlDatabase.LogToConsole)
|
|
82
|
-
console.info(sql);
|
|
83
|
-
return [4 /*yield*/, this.createCommand().execute(sql)];
|
|
84
|
-
case 2:
|
|
85
|
-
_a.sent();
|
|
86
|
-
return [2 /*return*/];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
WebSqlDataProvider.prototype.createTable = function (entity) {
|
|
92
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
93
|
-
var result, e, _a, _b, x, sql;
|
|
94
|
-
var e_2, _c;
|
|
95
|
-
return tslib_1.__generator(this, function (_d) {
|
|
96
|
-
switch (_d.label) {
|
|
97
|
-
case 0:
|
|
98
|
-
result = '';
|
|
99
|
-
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOf)(entity)];
|
|
100
|
-
case 1:
|
|
101
|
-
e = _d.sent();
|
|
102
|
-
try {
|
|
103
|
-
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
104
|
-
x = _b.value;
|
|
105
|
-
if (!(0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e) || (0, RepositoryImplementation_js_1.isAutoIncrement)(x)) {
|
|
106
|
-
if (result.length != 0)
|
|
107
|
-
result += ',';
|
|
108
|
-
result += '\r\n ';
|
|
109
|
-
if ((0, RepositoryImplementation_js_1.isAutoIncrement)(x)) {
|
|
110
|
-
if (x.key != entity.idMetadata.field.key)
|
|
111
|
-
throw 'in web sql, autoincrement is only allowed for primary key';
|
|
112
|
-
result += e.$dbNameOf(x) + ' integer primary key autoincrement';
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
result += this.addColumnSqlSyntax(x, e.$dbNameOf(x));
|
|
116
|
-
if (x.key == entity.idMetadata.field.key) {
|
|
117
|
-
result += ' primary key';
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
124
|
-
finally {
|
|
125
|
-
try {
|
|
126
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
127
|
-
}
|
|
128
|
-
finally { if (e_2) throw e_2.error; }
|
|
129
|
-
}
|
|
130
|
-
sql = 'create table if not exists ' + e.$entityName + ' (' + result + '\r\n)';
|
|
131
|
-
if (sql_database_js_1.SqlDatabase.LogToConsole)
|
|
132
|
-
console.log(sql);
|
|
133
|
-
return [4 /*yield*/, this.createCommand().execute(sql)];
|
|
134
|
-
case 2:
|
|
135
|
-
_d.sent();
|
|
136
|
-
return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
WebSqlDataProvider.prototype.createCommand = function () {
|
|
142
|
-
return new WebSqlBridgeToSQLCommand(this.db);
|
|
143
|
-
};
|
|
144
|
-
WebSqlDataProvider.prototype.transaction = function (action) {
|
|
145
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
146
|
-
return tslib_1.__generator(this, function (_a) {
|
|
147
|
-
throw new Error('Method not implemented.');
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
WebSqlDataProvider.prototype.addColumnSqlSyntax = function (x, dbName) {
|
|
152
|
-
var result = dbName;
|
|
153
|
-
var nullNumber = x.allowNull ? '' : ' default 0 not null';
|
|
154
|
-
if (x.valueType == Date)
|
|
155
|
-
result += ' integer';
|
|
156
|
-
else if (x.valueType == Boolean)
|
|
157
|
-
result += ' integer ' + nullNumber;
|
|
158
|
-
else if (x.valueType == Number) {
|
|
159
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
160
|
-
result += ' real ' + nullNumber;
|
|
161
|
-
else
|
|
162
|
-
result += ' ' + x.valueConverter.fieldTypeInDb + ' ' + nullNumber;
|
|
163
|
-
}
|
|
164
|
-
else
|
|
165
|
-
result += ' text' + (x.allowNull ? ' ' : " default '' not null ");
|
|
166
|
-
return result;
|
|
167
|
-
};
|
|
168
|
-
WebSqlDataProvider.prototype.toString = function () {
|
|
169
|
-
return 'WebSqlDataProvider';
|
|
170
|
-
};
|
|
171
|
-
return WebSqlDataProvider;
|
|
172
|
-
}());
|
|
173
|
-
exports.WebSqlDataProvider = WebSqlDataProvider;
|
|
174
|
-
var WebSqlBridgeToSQLCommand = /** @class */ (function () {
|
|
175
|
-
//@ts-ignore
|
|
176
|
-
function WebSqlBridgeToSQLCommand(source) {
|
|
177
|
-
this.source = source;
|
|
178
|
-
this.values = [];
|
|
179
|
-
}
|
|
180
|
-
WebSqlBridgeToSQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
|
|
181
|
-
return this.param(val);
|
|
182
|
-
};
|
|
183
|
-
WebSqlBridgeToSQLCommand.prototype.param = function (val) {
|
|
184
|
-
this.values.push(val);
|
|
185
|
-
return '~' + this.values.length + '~';
|
|
186
|
-
};
|
|
187
|
-
WebSqlBridgeToSQLCommand.prototype.execute = function (sql) {
|
|
188
|
-
var _this = this;
|
|
189
|
-
return new Promise(function (resolve, reject) {
|
|
190
|
-
return _this.source.transaction(function (t) {
|
|
191
|
-
var s = sql;
|
|
192
|
-
var v = [];
|
|
193
|
-
var m = s.match(/~\d+~/g);
|
|
194
|
-
if (m != null)
|
|
195
|
-
m.forEach(function (mr) {
|
|
196
|
-
s = s.replace(mr, '?');
|
|
197
|
-
v.push(_this.values[Number.parseInt(mr.substring(1, mr.length - 1)) - 1]);
|
|
198
|
-
});
|
|
199
|
-
t.executeSql(s, v, function (t1, r) { return resolve(new WebSqlBridgeToSQLQueryResult(r)); }, function (t2, err) {
|
|
200
|
-
reject(err.message);
|
|
201
|
-
return false;
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
return WebSqlBridgeToSQLCommand;
|
|
207
|
-
}());
|
|
208
|
-
var WebSqlBridgeToSQLQueryResult = /** @class */ (function () {
|
|
209
|
-
//@ts-ignore
|
|
210
|
-
function WebSqlBridgeToSQLQueryResult(r) {
|
|
211
|
-
this.r = r;
|
|
212
|
-
this.rows = [];
|
|
213
|
-
for (var i = 0; i < r.rows.length; i++) {
|
|
214
|
-
this.rows.push(r.rows.item(i));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
WebSqlBridgeToSQLQueryResult.prototype.getColumnKeyInResultForIndexInSelect = function (index) {
|
|
218
|
-
if (this.rows.length == 0)
|
|
219
|
-
throw Error('No rows');
|
|
220
|
-
var i = 0;
|
|
221
|
-
for (var m in this.rows[0]) {
|
|
222
|
-
if (i++ == index)
|
|
223
|
-
return m;
|
|
224
|
-
}
|
|
225
|
-
throw Error('index not found');
|
|
226
|
-
};
|
|
227
|
-
return WebSqlBridgeToSQLQueryResult;
|
|
228
|
-
}());
|