remult 0.25.8-exp.0 → 0.25.8-exp.1
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/migrations/generate-migrations.js +9 -5
- package/esm/migrations/migrate.js +25 -14
- package/esm/migrations/update-migrations-ts-file.js +1 -1
- package/esm/postgres/postgres-data-provider.js +11 -2
- package/esm/remult-knex/index.js +4 -0
- package/esm/remult-sql-js.js +5 -0
- package/esm/src/data-providers/sql-database.js +5 -1
- package/esm/src/data-providers/web-sql-data-provider.js +1 -9
- package/esm/src/remult3/remult3.js +7 -1
- package/migrations/generate-migrations.d.ts +5 -4
- package/migrations/generate-migrations.js +12 -6
- package/migrations/migrate.d.ts +3 -2
- package/migrations/migrate.js +63 -51
- package/migrations/update-migrations-ts-file.js +1 -1
- package/package.json +1 -1
- package/postgres/postgres-data-provider.d.ts +3 -0
- package/postgres/postgres-data-provider.js +11 -2
- package/remult-knex/index.d.ts +2 -2
- package/remult-knex/index.js +4 -0
- package/remult-sql-js.d.ts +2 -0
- package/remult-sql-js.js +14 -0
- package/src/data-providers/sql-database.d.ts +2 -3
- package/src/data-providers/sql-database.js +3 -0
- package/src/data-providers/web-sql-data-provider.d.ts +1 -2
- package/src/data-providers/web-sql-data-provider.js +4 -8
- package/src/remult3/remult3.js +7 -1
- package/src/sql-command.d.ts +1 -0
|
@@ -4,12 +4,13 @@ import { compareMigrationSnapshot, emptySnapshot, } from './compare-migration-sn
|
|
|
4
4
|
import { updateMigrationsFile } from './update-migrations-ts-file.js';
|
|
5
5
|
import { DefaultMigrationBuilder, } from './migration-types.js';
|
|
6
6
|
import { isOfType } from '../src/isOfType.js';
|
|
7
|
+
import { initDataProvider } from '../server/initDataProvider.js';
|
|
7
8
|
export async function generateMigrations(options) {
|
|
8
|
-
const migrationDir = options.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const migrationsTSFilename = options.
|
|
12
|
-
const dataProvider = await options.dataProvider;
|
|
9
|
+
const migrationDir = options.migrationsFolder ||
|
|
10
|
+
path.join(process.cwd(), 'src/server/migrations');
|
|
11
|
+
const snapshotFileName = options.snapshotFile || path.join(migrationDir, 'migrations-snapshot.json');
|
|
12
|
+
const migrationsTSFilename = options.migrationsTSFile || path.join(migrationDir, 'migrations.ts');
|
|
13
|
+
const dataProvider = await initDataProvider(options.dataProvider);
|
|
13
14
|
for (const p of [snapshotFileName, migrationsTSFilename]) {
|
|
14
15
|
if (!fs.existsSync(path.dirname(p))) {
|
|
15
16
|
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
@@ -44,4 +45,7 @@ export async function generateMigrations(options) {
|
|
|
44
45
|
`async (${hasSql ? '{sql}' : ''})=>{\n${steps.join('\n')}\n}`,
|
|
45
46
|
]);
|
|
46
47
|
fs.writeFileSync(snapshotFileName, JSON.stringify(snapshot, null, 2));
|
|
48
|
+
if (options.endConnection !== false && isOfType(dataProvider, 'end')) {
|
|
49
|
+
await dataProvider.end();
|
|
50
|
+
}
|
|
47
51
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Entity, IdEntity, Fields, remult, Remult, } from '../index.js';
|
|
3
|
+
import { initDataProvider } from '../server/initDataProvider.js';
|
|
3
4
|
import { doTransaction } from '../src/context.js';
|
|
4
|
-
import { cast } from '../src/isOfType.js';
|
|
5
|
+
import { cast, isOfType } from '../src/isOfType.js';
|
|
5
6
|
export async function migrate(options) {
|
|
6
|
-
let migrationTableName = options.
|
|
7
|
-
const dataProvider = options.dataProvider
|
|
8
|
-
? await options.dataProvider
|
|
9
|
-
: remult.dataProvider;
|
|
7
|
+
let migrationTableName = options.migrationsTable || '__remult_migrations_version';
|
|
8
|
+
const dataProvider = await initDataProvider(options.dataProvider);
|
|
10
9
|
const prev = remult.dataProvider;
|
|
11
10
|
remult.dataProvider = dataProvider;
|
|
12
11
|
try {
|
|
@@ -36,15 +35,24 @@ export async function migrate(options) {
|
|
|
36
35
|
throw new Error('Migration step number must be a non-negative integer');
|
|
37
36
|
if (v.version >= step)
|
|
38
37
|
continue;
|
|
39
|
-
console.info('Executing migration step'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
console.info('Executing migration step ' + step);
|
|
39
|
+
console.time('Completed migration step ' + step);
|
|
40
|
+
try {
|
|
41
|
+
await doTransaction(remult, async (dp) => {
|
|
42
|
+
const utils = {
|
|
43
|
+
sql: async (sql) => {
|
|
44
|
+
await cast(dp, 'execute').execute(sql);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
await action(utils);
|
|
48
|
+
});
|
|
49
|
+
console.timeEnd('Completed migration step ' + step);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error('Failed to execute migration step ' + step);
|
|
53
|
+
console.error(err);
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
48
56
|
v.version = step;
|
|
49
57
|
await v.save();
|
|
50
58
|
}
|
|
@@ -52,4 +60,7 @@ export async function migrate(options) {
|
|
|
52
60
|
finally {
|
|
53
61
|
remult.dataProvider = prev;
|
|
54
62
|
}
|
|
63
|
+
if (options.endConnection !== false && isOfType(dataProvider, 'end')) {
|
|
64
|
+
await dataProvider.end();
|
|
65
|
+
}
|
|
55
66
|
}
|
|
@@ -10,7 +10,7 @@ export async function updateMigrationsFile(filePath, steps) {
|
|
|
10
10
|
fs.writeFileSync(filePath, '');
|
|
11
11
|
}
|
|
12
12
|
const importPath = 'remult/migrations';
|
|
13
|
-
const importName = '
|
|
13
|
+
const importName = 'Migrations';
|
|
14
14
|
// Load the file
|
|
15
15
|
const sourceFile = ts.createSourceFile(filePath, fs.readFileSync(filePath).toString(), ts.ScriptTarget.Latest, true);
|
|
16
16
|
let migrationsExportFound = false;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { remult as defaultRemult } from '../src/remult-proxy.js';
|
|
1
2
|
import pg from 'pg';
|
|
2
3
|
const { Pool } = pg;
|
|
3
4
|
import { Remult } from '../src/context.js';
|
|
@@ -8,8 +9,10 @@ export class PostgresDataProvider {
|
|
|
8
9
|
options;
|
|
9
10
|
supportsJsonColumnType = true;
|
|
10
11
|
static getDb(remult) {
|
|
11
|
-
const
|
|
12
|
-
|
|
12
|
+
const r = (remult || defaultRemult).dataProvider;
|
|
13
|
+
if (!r._getSourceSql)
|
|
14
|
+
throw 'the data provider is not an SqlDatabase';
|
|
15
|
+
const me = r._getSourceSql();
|
|
13
16
|
if (!me.pool) {
|
|
14
17
|
throw 'the data provider is not a PostgresDataProvider';
|
|
15
18
|
}
|
|
@@ -35,6 +38,9 @@ export class PostgresDataProvider {
|
|
|
35
38
|
this.pool = new PostgresSchemaWrapper(pool, options.schema);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
end() {
|
|
42
|
+
return this.pool.end();
|
|
43
|
+
}
|
|
38
44
|
provideMigrationBuilder(builder) {
|
|
39
45
|
var db = new SqlDatabase(this);
|
|
40
46
|
var sb = new PostgresSchemaBuilder(db, this.options?.schema);
|
|
@@ -184,4 +190,7 @@ export class PostgresSchemaWrapper {
|
|
|
184
190
|
c.release();
|
|
185
191
|
}
|
|
186
192
|
}
|
|
193
|
+
end() {
|
|
194
|
+
return this.pool.end();
|
|
195
|
+
}
|
|
187
196
|
}
|
package/esm/remult-knex/index.js
CHANGED
package/esm/remult-sql-js.js
CHANGED
|
@@ -76,6 +76,7 @@ export class SqlDatabase {
|
|
|
76
76
|
transaction: (z) => x.transaction(z),
|
|
77
77
|
supportsJsonColumnType: this.sql.supportsJsonColumnType,
|
|
78
78
|
wrapIdentifier: this.wrapIdentifier,
|
|
79
|
+
end: this.end,
|
|
79
80
|
}));
|
|
80
81
|
}
|
|
81
82
|
finally {
|
|
@@ -121,10 +122,13 @@ export class SqlDatabase {
|
|
|
121
122
|
if (isOfType(sql, 'provideMigrationBuilder')) {
|
|
122
123
|
this.provideMigrationBuilder = sql.provideMigrationBuilder;
|
|
123
124
|
}
|
|
125
|
+
if (isOfType(sql, 'end'))
|
|
126
|
+
this.end = () => sql.end();
|
|
124
127
|
}
|
|
128
|
+
/* @internal */
|
|
125
129
|
provideMigrationBuilder;
|
|
126
|
-
isProxy;
|
|
127
130
|
createdEntities = [];
|
|
131
|
+
end;
|
|
128
132
|
}
|
|
129
133
|
const icons = new Map([
|
|
130
134
|
// CRUD
|
|
@@ -13,15 +13,7 @@ export class WebSqlDataProvider {
|
|
|
13
13
|
//@ts-ignore
|
|
14
14
|
this.db = window.openDatabase(databaseName, '1.0', databaseName, databaseSize);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
static getDb(remult) {
|
|
18
|
-
const sql = SqlDatabase.getDb(remult);
|
|
19
|
-
const me = sql._getSourceSql();
|
|
20
|
-
if (!me.db) {
|
|
21
|
-
throw 'the data provider is not a WebSqlDataProvider';
|
|
22
|
-
}
|
|
23
|
-
return me.db;
|
|
24
|
-
}
|
|
16
|
+
async end() { }
|
|
25
17
|
getLimitSqlSyntax(limit, offset) {
|
|
26
18
|
return ' limit ' + limit + ' offset ' + offset;
|
|
27
19
|
}
|
|
@@ -11,7 +11,7 @@ https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0O
|
|
|
11
11
|
*/
|
|
12
12
|
//p1 - cleanup root directory of reult
|
|
13
13
|
//p1 - in this video I'll use remult to turn a frontend app to a fullstack app
|
|
14
|
-
/*
|
|
14
|
+
/*p1 - discuss using delete & put - with url query language for deleteMany and updateMany -
|
|
15
15
|
- put & delete, similar to get
|
|
16
16
|
- add where to count, deleteMany,updateMany,
|
|
17
17
|
- prevent delete all and update all - must have meaningful where.
|
|
@@ -20,6 +20,12 @@ https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0O
|
|
|
20
20
|
- protect against deleting of all rows by mistake
|
|
21
21
|
- https://github.com/remult/remult/issues/221#issuecomment-2016519746
|
|
22
22
|
|
|
23
|
+
*/
|
|
24
|
+
/*p1 - I want to change the signature of getDb from getting optional remult, to getting optional dataProvider.
|
|
25
|
+
|
|
26
|
+
In most cases you will not send anything - and it'll be by default remult.dataProvider.
|
|
27
|
+
|
|
28
|
+
I just findmyself creating remults to extract the data provider :)
|
|
23
29
|
*/
|
|
24
30
|
//y1 - getFields didn't work for kobi in the home component
|
|
25
31
|
//p1 - add section to Fields doc, explaining field type in db
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DataProvider } from '../index.js';
|
|
2
2
|
export declare function generateMigrations(options: {
|
|
3
3
|
entities: any[];
|
|
4
|
-
dataProvider: Promise<DataProvider> | DataProvider;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
dataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
5
|
+
migrationsFolder?: string;
|
|
6
|
+
snapshotFile?: string;
|
|
7
|
+
migrationsTSFile?: string;
|
|
8
|
+
endConnection?: boolean;
|
|
8
9
|
}): Promise<void>;
|
|
@@ -8,6 +8,7 @@ var compare_migration_snapshots_js_1 = require("./compare-migration-snapshots.js
|
|
|
8
8
|
var update_migrations_ts_file_js_1 = require("./update-migrations-ts-file.js");
|
|
9
9
|
var migration_types_js_1 = require("./migration-types.js");
|
|
10
10
|
var isOfType_js_1 = require("../src/isOfType.js");
|
|
11
|
+
var initDataProvider_js_1 = require("../server/initDataProvider.js");
|
|
11
12
|
function generateMigrations(options) {
|
|
12
13
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
13
14
|
var migrationDir, snapshotFileName, migrationsTSFilename, dataProvider, _a, _b, p, snapshot, hasSql, steps, code, migrationBuilder;
|
|
@@ -15,11 +16,11 @@ function generateMigrations(options) {
|
|
|
15
16
|
return tslib_1.__generator(this, function (_d) {
|
|
16
17
|
switch (_d.label) {
|
|
17
18
|
case 0:
|
|
18
|
-
migrationDir = options.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
migrationsTSFilename = options.
|
|
22
|
-
return [4 /*yield*/, options.dataProvider];
|
|
19
|
+
migrationDir = options.migrationsFolder ||
|
|
20
|
+
path_1.default.join(process.cwd(), 'src/server/migrations');
|
|
21
|
+
snapshotFileName = options.snapshotFile || path_1.default.join(migrationDir, 'migrations-snapshot.json');
|
|
22
|
+
migrationsTSFilename = options.migrationsTSFile || path_1.default.join(migrationDir, 'migrations.ts');
|
|
23
|
+
return [4 /*yield*/, (0, initDataProvider_js_1.initDataProvider)(options.dataProvider)];
|
|
23
24
|
case 1:
|
|
24
25
|
dataProvider = _d.sent();
|
|
25
26
|
try {
|
|
@@ -74,7 +75,12 @@ function generateMigrations(options) {
|
|
|
74
75
|
_d.label = 4;
|
|
75
76
|
case 4:
|
|
76
77
|
fs_1.default.writeFileSync(snapshotFileName, JSON.stringify(snapshot, null, 2));
|
|
77
|
-
return [
|
|
78
|
+
if (!(options.endConnection !== false && (0, isOfType_js_1.isOfType)(dataProvider, 'end'))) return [3 /*break*/, 6];
|
|
79
|
+
return [4 /*yield*/, dataProvider.end()];
|
|
80
|
+
case 5:
|
|
81
|
+
_d.sent();
|
|
82
|
+
_d.label = 6;
|
|
83
|
+
case 6: return [2 /*return*/];
|
|
78
84
|
}
|
|
79
85
|
});
|
|
80
86
|
});
|
package/migrations/migrate.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type DataProvider } from '../index.js';
|
|
|
2
2
|
import type { Migrations } from './migration-types.js';
|
|
3
3
|
export declare function migrate(options: {
|
|
4
4
|
migrations: Migrations;
|
|
5
|
-
dataProvider
|
|
6
|
-
|
|
5
|
+
dataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
6
|
+
migrationsTable?: string;
|
|
7
|
+
endConnection?: boolean;
|
|
7
8
|
}): Promise<void>;
|
package/migrations/migrate.js
CHANGED
|
@@ -3,32 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.migrate = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var index_js_1 = require("../index.js");
|
|
6
|
+
var initDataProvider_js_1 = require("../server/initDataProvider.js");
|
|
6
7
|
var context_js_1 = require("../src/context.js");
|
|
7
8
|
var isOfType_js_1 = require("../src/isOfType.js");
|
|
8
9
|
function migrate(options) {
|
|
9
10
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
10
|
-
var migrationTableName, dataProvider,
|
|
11
|
-
var e_1,
|
|
11
|
+
var migrationTableName, dataProvider, prev, VersionInfo, repo, v, steps, _loop_1, steps_1, steps_1_1, _a, stepText, action, e_1_1;
|
|
12
|
+
var e_1, _b;
|
|
12
13
|
var _this = this;
|
|
13
|
-
return tslib_1.__generator(this, function (
|
|
14
|
-
switch (
|
|
14
|
+
return tslib_1.__generator(this, function (_c) {
|
|
15
|
+
switch (_c.label) {
|
|
15
16
|
case 0:
|
|
16
|
-
migrationTableName = options.
|
|
17
|
-
|
|
18
|
-
return [4 /*yield*/, options.dataProvider];
|
|
17
|
+
migrationTableName = options.migrationsTable || '__remult_migrations_version';
|
|
18
|
+
return [4 /*yield*/, (0, initDataProvider_js_1.initDataProvider)(options.dataProvider)];
|
|
19
19
|
case 1:
|
|
20
|
-
|
|
21
|
-
return [3 /*break*/, 3];
|
|
22
|
-
case 2:
|
|
23
|
-
_a = index_js_1.remult.dataProvider;
|
|
24
|
-
_d.label = 3;
|
|
25
|
-
case 3:
|
|
26
|
-
dataProvider = _a;
|
|
20
|
+
dataProvider = _c.sent();
|
|
27
21
|
prev = index_js_1.remult.dataProvider;
|
|
28
22
|
index_js_1.remult.dataProvider = dataProvider;
|
|
29
|
-
|
|
30
|
-
case
|
|
31
|
-
|
|
23
|
+
_c.label = 2;
|
|
24
|
+
case 2:
|
|
25
|
+
_c.trys.push([2, , 14, 15]);
|
|
32
26
|
VersionInfo = /** @class */ (function (_super) {
|
|
33
27
|
tslib_1.__extends(VersionInfo, _super);
|
|
34
28
|
function VersionInfo() {
|
|
@@ -46,14 +40,14 @@ function migrate(options) {
|
|
|
46
40
|
return VersionInfo;
|
|
47
41
|
}(index_js_1.IdEntity));
|
|
48
42
|
repo = new index_js_1.Remult(dataProvider).repo(VersionInfo);
|
|
49
|
-
if (!dataProvider.ensureSchema) return [3 /*break*/,
|
|
43
|
+
if (!dataProvider.ensureSchema) return [3 /*break*/, 4];
|
|
50
44
|
return [4 /*yield*/, dataProvider.ensureSchema([repo.metadata])];
|
|
45
|
+
case 3:
|
|
46
|
+
_c.sent();
|
|
47
|
+
_c.label = 4;
|
|
48
|
+
case 4: return [4 /*yield*/, repo.findFirst()];
|
|
51
49
|
case 5:
|
|
52
|
-
|
|
53
|
-
_d.label = 6;
|
|
54
|
-
case 6: return [4 /*yield*/, repo.findFirst()];
|
|
55
|
-
case 7:
|
|
56
|
-
v = _d.sent();
|
|
50
|
+
v = _c.sent();
|
|
57
51
|
if (!v) {
|
|
58
52
|
v = repo.create();
|
|
59
53
|
v.version = -1;
|
|
@@ -64,16 +58,20 @@ function migrate(options) {
|
|
|
64
58
|
return parseInt(a) - parseInt(b);
|
|
65
59
|
});
|
|
66
60
|
_loop_1 = function (stepText, action) {
|
|
67
|
-
var step;
|
|
68
|
-
return tslib_1.__generator(this, function (
|
|
69
|
-
switch (
|
|
61
|
+
var step, err_1;
|
|
62
|
+
return tslib_1.__generator(this, function (_d) {
|
|
63
|
+
switch (_d.label) {
|
|
70
64
|
case 0:
|
|
71
65
|
step = parseInt(stepText);
|
|
72
66
|
if (step < 0)
|
|
73
67
|
throw new Error('Migration step number must be a non-negative integer');
|
|
74
68
|
if (v.version >= step)
|
|
75
69
|
return [2 /*return*/, "continue"];
|
|
76
|
-
console.info('Executing migration step'
|
|
70
|
+
console.info('Executing migration step ' + step);
|
|
71
|
+
console.time('Completed migration step ' + step);
|
|
72
|
+
_d.label = 1;
|
|
73
|
+
case 1:
|
|
74
|
+
_d.trys.push([1, 3, , 4]);
|
|
77
75
|
return [4 /*yield*/, (0, context_js_1.doTransaction)(index_js_1.remult, function (dp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
78
76
|
var utils;
|
|
79
77
|
var _this = this;
|
|
@@ -99,46 +97,60 @@ function migrate(options) {
|
|
|
99
97
|
}
|
|
100
98
|
});
|
|
101
99
|
}); })];
|
|
102
|
-
case
|
|
103
|
-
|
|
100
|
+
case 2:
|
|
101
|
+
_d.sent();
|
|
102
|
+
console.timeEnd('Completed migration step ' + step);
|
|
103
|
+
return [3 /*break*/, 4];
|
|
104
|
+
case 3:
|
|
105
|
+
err_1 = _d.sent();
|
|
106
|
+
console.error('Failed to execute migration step ' + step);
|
|
107
|
+
console.error(err_1);
|
|
108
|
+
throw err_1;
|
|
109
|
+
case 4:
|
|
104
110
|
v.version = step;
|
|
105
111
|
return [4 /*yield*/, v.save()];
|
|
106
|
-
case
|
|
107
|
-
|
|
112
|
+
case 5:
|
|
113
|
+
_d.sent();
|
|
108
114
|
return [2 /*return*/];
|
|
109
115
|
}
|
|
110
116
|
});
|
|
111
117
|
};
|
|
112
|
-
|
|
113
|
-
case
|
|
114
|
-
|
|
118
|
+
_c.label = 6;
|
|
119
|
+
case 6:
|
|
120
|
+
_c.trys.push([6, 11, 12, 13]);
|
|
115
121
|
steps_1 = tslib_1.__values(steps), steps_1_1 = steps_1.next();
|
|
116
|
-
|
|
117
|
-
case
|
|
118
|
-
if (!!steps_1_1.done) return [3 /*break*/,
|
|
119
|
-
|
|
122
|
+
_c.label = 7;
|
|
123
|
+
case 7:
|
|
124
|
+
if (!!steps_1_1.done) return [3 /*break*/, 10];
|
|
125
|
+
_a = tslib_1.__read(steps_1_1.value, 2), stepText = _a[0], action = _a[1];
|
|
120
126
|
return [5 /*yield**/, _loop_1(stepText, action)];
|
|
121
|
-
case
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
case
|
|
127
|
+
case 8:
|
|
128
|
+
_c.sent();
|
|
129
|
+
_c.label = 9;
|
|
130
|
+
case 9:
|
|
125
131
|
steps_1_1 = steps_1.next();
|
|
126
|
-
return [3 /*break*/,
|
|
127
|
-
case
|
|
128
|
-
case
|
|
129
|
-
e_1_1 =
|
|
132
|
+
return [3 /*break*/, 7];
|
|
133
|
+
case 10: return [3 /*break*/, 13];
|
|
134
|
+
case 11:
|
|
135
|
+
e_1_1 = _c.sent();
|
|
130
136
|
e_1 = { error: e_1_1 };
|
|
131
|
-
return [3 /*break*/,
|
|
132
|
-
case
|
|
137
|
+
return [3 /*break*/, 13];
|
|
138
|
+
case 12:
|
|
133
139
|
try {
|
|
134
|
-
if (steps_1_1 && !steps_1_1.done && (
|
|
140
|
+
if (steps_1_1 && !steps_1_1.done && (_b = steps_1.return)) _b.call(steps_1);
|
|
135
141
|
}
|
|
136
142
|
finally { if (e_1) throw e_1.error; }
|
|
137
143
|
return [7 /*endfinally*/];
|
|
138
|
-
case
|
|
139
|
-
case
|
|
144
|
+
case 13: return [3 /*break*/, 15];
|
|
145
|
+
case 14:
|
|
140
146
|
index_js_1.remult.dataProvider = prev;
|
|
141
147
|
return [7 /*endfinally*/];
|
|
148
|
+
case 15:
|
|
149
|
+
if (!(options.endConnection !== false && (0, isOfType_js_1.isOfType)(dataProvider, 'end'))) return [3 /*break*/, 17];
|
|
150
|
+
return [4 /*yield*/, dataProvider.end()];
|
|
151
|
+
case 16:
|
|
152
|
+
_c.sent();
|
|
153
|
+
_c.label = 17;
|
|
142
154
|
case 17: return [2 /*return*/];
|
|
143
155
|
}
|
|
144
156
|
});
|
|
@@ -21,7 +21,7 @@ function updateMigrationsFile(filePath, steps) {
|
|
|
21
21
|
fs.writeFileSync(filePath, '');
|
|
22
22
|
}
|
|
23
23
|
importPath = 'remult/migrations';
|
|
24
|
-
importName = '
|
|
24
|
+
importName = 'Migrations';
|
|
25
25
|
sourceFile = ts.createSourceFile(filePath, fs.readFileSync(filePath).toString(), ts.ScriptTarget.Latest, true);
|
|
26
26
|
migrationsExportFound = false;
|
|
27
27
|
updatedSourceFile = ts.transform(sourceFile, [
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import type { SqlCommand, SqlImplementation } from '../src/sql-command.js';
|
|
|
6
6
|
import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from '../migrations/migration-types.js';
|
|
7
7
|
export interface PostgresPool extends PostgresCommandSource {
|
|
8
8
|
connect(): Promise<PostgresClient>;
|
|
9
|
+
end(): Promise<void>;
|
|
9
10
|
}
|
|
10
11
|
export interface PostgresClient extends PostgresCommandSource {
|
|
11
12
|
release(): void;
|
|
@@ -24,6 +25,7 @@ export declare class PostgresDataProvider implements SqlImplementation, CanBuild
|
|
|
24
25
|
schema?: string;
|
|
25
26
|
orderByNullsFirst?: boolean;
|
|
26
27
|
});
|
|
28
|
+
end(): Promise<void>;
|
|
27
29
|
provideMigrationBuilder(builder: MigrationCode): MigrationBuilder;
|
|
28
30
|
wrapIdentifier: (name: any) => any;
|
|
29
31
|
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
@@ -50,4 +52,5 @@ export declare class PostgresSchemaWrapper implements PostgresPool {
|
|
|
50
52
|
constructor(pool: PostgresPool, schema: string);
|
|
51
53
|
connect(): Promise<PostgresClient>;
|
|
52
54
|
query(queryText: string, values?: any[]): Promise<QueryResult>;
|
|
55
|
+
end(): Promise<void>;
|
|
53
56
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PostgresSchemaWrapper = exports.preparePostgresQueueStorage = exports.createPostgresDataProvider = exports.createPostgresConnection = exports.PostgresDataProvider = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var remult_proxy_js_1 = require("../src/remult-proxy.js");
|
|
5
6
|
var pg_1 = tslib_1.__importDefault(require("pg"));
|
|
6
7
|
var Pool = pg_1.default.Pool;
|
|
7
8
|
var context_js_1 = require("../src/context.js");
|
|
@@ -31,8 +32,10 @@ var PostgresDataProvider = /** @class */ (function () {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
PostgresDataProvider.getDb = function (remult) {
|
|
34
|
-
var
|
|
35
|
-
|
|
35
|
+
var r = (remult || remult_proxy_js_1.remult).dataProvider;
|
|
36
|
+
if (!r._getSourceSql)
|
|
37
|
+
throw 'the data provider is not an SqlDatabase';
|
|
38
|
+
var me = r._getSourceSql();
|
|
36
39
|
if (!me.pool) {
|
|
37
40
|
throw 'the data provider is not a PostgresDataProvider';
|
|
38
41
|
}
|
|
@@ -49,6 +52,9 @@ var PostgresDataProvider = /** @class */ (function () {
|
|
|
49
52
|
PostgresDataProvider.prototype.createCommand = function () {
|
|
50
53
|
return new PostgresBridgeToSQLCommand(this.pool);
|
|
51
54
|
};
|
|
55
|
+
PostgresDataProvider.prototype.end = function () {
|
|
56
|
+
return this.pool.end();
|
|
57
|
+
};
|
|
52
58
|
PostgresDataProvider.prototype.provideMigrationBuilder = function (builder) {
|
|
53
59
|
var _this = this;
|
|
54
60
|
var _a;
|
|
@@ -299,6 +305,9 @@ var PostgresSchemaWrapper = /** @class */ (function () {
|
|
|
299
305
|
});
|
|
300
306
|
});
|
|
301
307
|
};
|
|
308
|
+
PostgresSchemaWrapper.prototype.end = function () {
|
|
309
|
+
return this.pool.end();
|
|
310
|
+
};
|
|
302
311
|
return PostgresSchemaWrapper;
|
|
303
312
|
}());
|
|
304
313
|
exports.PostgresSchemaWrapper = PostgresSchemaWrapper;
|
package/remult-knex/index.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ import type { DataProvider, EntityDataProvider } from '../src/data-interfaces.js
|
|
|
6
6
|
import type { EntityFilter, EntityMetadata } from '../src/remult3/remult3.js';
|
|
7
7
|
import type { RepositoryOverloads } from '../src/remult3/RepositoryImplementation.js';
|
|
8
8
|
import type { HasWrapIdentifier, SqlCommand, SqlCommandFactory, SqlResult } from '../src/sql-command.js';
|
|
9
|
-
import type { CanBuildMigrations
|
|
9
|
+
import type { CanBuildMigrations } from '../migrations/migration-types.js';
|
|
10
10
|
export declare class KnexDataProvider implements DataProvider, HasWrapIdentifier, SqlCommandFactory, CanBuildMigrations {
|
|
11
11
|
knex: Knex;
|
|
12
12
|
constructor(knex: Knex);
|
|
13
|
-
|
|
13
|
+
end(): Promise<void>;
|
|
14
14
|
createCommand(): SqlCommand;
|
|
15
15
|
execute(sql: string): Promise<SqlResult>;
|
|
16
16
|
static getDb(remult?: Remult): Knex<any, any[]>;
|
package/remult-knex/index.js
CHANGED
|
@@ -18,6 +18,10 @@ var KnexDataProvider = /** @class */ (function () {
|
|
|
18
18
|
this.knex = knex;
|
|
19
19
|
this.wrapIdentifier = function (x) { return _this.knex.ref(x) + ''; };
|
|
20
20
|
}
|
|
21
|
+
KnexDataProvider.prototype.end = function () {
|
|
22
|
+
return this.knex.destroy();
|
|
23
|
+
};
|
|
24
|
+
/* @internal */
|
|
21
25
|
KnexDataProvider.prototype.provideMigrationBuilder = function (builder) {
|
|
22
26
|
var sb = new KnexSchemaBuilder(this.knex);
|
|
23
27
|
return {
|
package/remult-sql-js.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { Database } from 'sql.js';
|
|
|
4
4
|
export declare class SqlJsDataProvider implements SqlImplementation {
|
|
5
5
|
private db;
|
|
6
6
|
constructor(db: Promise<Database>);
|
|
7
|
+
orderByNullsFirst?: boolean;
|
|
8
|
+
end(): Promise<void>;
|
|
7
9
|
getLimitSqlSyntax(limit: number, offset: number): string;
|
|
8
10
|
afterMutation?: VoidFunction;
|
|
9
11
|
createCommand(): SqlCommand;
|
package/remult-sql-js.js
CHANGED
|
@@ -9,6 +9,20 @@ var SqlJsDataProvider = /** @class */ (function () {
|
|
|
9
9
|
function SqlJsDataProvider(db) {
|
|
10
10
|
this.db = db;
|
|
11
11
|
}
|
|
12
|
+
SqlJsDataProvider.prototype.end = function () {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
14
|
+
return tslib_1.__generator(this, function (_a) {
|
|
15
|
+
switch (_a.label) {
|
|
16
|
+
case 0:
|
|
17
|
+
;
|
|
18
|
+
return [4 /*yield*/, this.db];
|
|
19
|
+
case 1:
|
|
20
|
+
(_a.sent()).close();
|
|
21
|
+
return [2 /*return*/];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
|
12
26
|
SqlJsDataProvider.prototype.getLimitSqlSyntax = function (limit, offset) {
|
|
13
27
|
return ' limit ' + limit + ' offset ' + offset;
|
|
14
28
|
};
|
|
@@ -4,7 +4,7 @@ import type { Remult } from '../context.js';
|
|
|
4
4
|
import type { CustomSqlFilterBuilderFunction, EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request.js';
|
|
5
5
|
import type { EntityFilter, EntityMetadata } from '../remult3/remult3.js';
|
|
6
6
|
import type { RepositoryOverloads } from '../remult3/RepositoryImplementation.js';
|
|
7
|
-
import type { CanBuildMigrations
|
|
7
|
+
import type { CanBuildMigrations } from '../../migrations/migration-types.js';
|
|
8
8
|
export declare class SqlDatabase implements DataProvider, HasWrapIdentifier, CanBuildMigrations, SqlCommandFactory {
|
|
9
9
|
private sql;
|
|
10
10
|
static getDb(remult?: Remult): SqlDatabase;
|
|
@@ -31,7 +31,6 @@ export declare class SqlDatabase implements DataProvider, HasWrapIdentifier, Can
|
|
|
31
31
|
*/
|
|
32
32
|
static durationThreshold: number;
|
|
33
33
|
constructor(sql: SqlImplementation);
|
|
34
|
-
provideMigrationBuilder: (builder: MigrationCode) => MigrationBuilder;
|
|
35
|
-
isProxy?: boolean;
|
|
36
34
|
private createdEntities;
|
|
35
|
+
end: () => Promise<void>;
|
|
37
36
|
}
|
|
@@ -22,6 +22,8 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
22
22
|
if ((0, isOfType_js_1.isOfType)(sql, 'provideMigrationBuilder')) {
|
|
23
23
|
this.provideMigrationBuilder = sql.provideMigrationBuilder;
|
|
24
24
|
}
|
|
25
|
+
if ((0, isOfType_js_1.isOfType)(sql, 'end'))
|
|
26
|
+
this.end = function () { return sql.end(); };
|
|
25
27
|
}
|
|
26
28
|
SqlDatabase.getDb = function (remult) {
|
|
27
29
|
var r = (remult || remult_proxy_js_1.remult).dataProvider;
|
|
@@ -134,6 +136,7 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
134
136
|
transaction: function (z) { return x.transaction(z); },
|
|
135
137
|
supportsJsonColumnType: this.sql.supportsJsonColumnType,
|
|
136
138
|
wrapIdentifier: this.wrapIdentifier,
|
|
139
|
+
end: this.end,
|
|
137
140
|
}))];
|
|
138
141
|
case 2:
|
|
139
142
|
_a.sent();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { __RowsOfDataForTesting } from '../__RowsOfDataForTesting.js';
|
|
2
2
|
import type { SqlCommand, SqlImplementation } from '../sql-command.js';
|
|
3
|
-
import type { Remult } from '../context.js';
|
|
4
3
|
import type { EntityMetadata } from '../remult3/remult3.js';
|
|
5
4
|
export declare class WebSqlDataProvider implements SqlImplementation, __RowsOfDataForTesting {
|
|
6
5
|
private databaseName;
|
|
@@ -8,7 +7,7 @@ export declare class WebSqlDataProvider implements SqlImplementation, __RowsOfDa
|
|
|
8
7
|
[tableName: string]: any;
|
|
9
8
|
};
|
|
10
9
|
constructor(databaseName: string, databaseSize?: number);
|
|
11
|
-
|
|
10
|
+
end(): Promise<void>;
|
|
12
11
|
getLimitSqlSyntax(limit: number, offset: number): string;
|
|
13
12
|
entityIsUsedForTheFirstTime(entity: EntityMetadata): Promise<void>;
|
|
14
13
|
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
@@ -13,14 +13,10 @@ var WebSqlDataProvider = /** @class */ (function () {
|
|
|
13
13
|
//@ts-ignore
|
|
14
14
|
this.db = window.openDatabase(databaseName, '1.0', databaseName, databaseSize);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!me.db) {
|
|
21
|
-
throw 'the data provider is not a WebSqlDataProvider';
|
|
22
|
-
}
|
|
23
|
-
return me.db;
|
|
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
|
+
}); });
|
|
24
20
|
};
|
|
25
21
|
WebSqlDataProvider.prototype.getLimitSqlSyntax = function (limit, offset) {
|
|
26
22
|
return ' limit ' + limit + ' offset ' + offset;
|
package/src/remult3/remult3.js
CHANGED
|
@@ -12,7 +12,7 @@ https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0O
|
|
|
12
12
|
*/
|
|
13
13
|
//p1 - cleanup root directory of reult
|
|
14
14
|
//p1 - in this video I'll use remult to turn a frontend app to a fullstack app
|
|
15
|
-
/*
|
|
15
|
+
/*p1 - discuss using delete & put - with url query language for deleteMany and updateMany -
|
|
16
16
|
- put & delete, similar to get
|
|
17
17
|
- add where to count, deleteMany,updateMany,
|
|
18
18
|
- prevent delete all and update all - must have meaningful where.
|
|
@@ -21,6 +21,12 @@ https://gitkraken.dev/link/dnNjb2RlOi8vZWFtb2Rpby5naXRsZW5zL2xpbmsvci9mMDgzMWU0O
|
|
|
21
21
|
- protect against deleting of all rows by mistake
|
|
22
22
|
- https://github.com/remult/remult/issues/221#issuecomment-2016519746
|
|
23
23
|
|
|
24
|
+
*/
|
|
25
|
+
/*p1 - I want to change the signature of getDb from getting optional remult, to getting optional dataProvider.
|
|
26
|
+
|
|
27
|
+
In most cases you will not send anything - and it'll be by default remult.dataProvider.
|
|
28
|
+
|
|
29
|
+
I just findmyself creating remults to extract the data provider :)
|
|
24
30
|
*/
|
|
25
31
|
//y1 - getFields didn't work for kobi in the home component
|
|
26
32
|
//p1 - add section to Fields doc, explaining field type in db
|
package/src/sql-command.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface SqlImplementation extends HasWrapIdentifier {
|
|
|
7
7
|
ensureSchema?(entities: EntityMetadata[]): Promise<void>;
|
|
8
8
|
supportsJsonColumnType?: boolean;
|
|
9
9
|
orderByNullsFirst?: boolean;
|
|
10
|
+
end(): Promise<void>;
|
|
10
11
|
afterMutation?: VoidFunction;
|
|
11
12
|
}
|
|
12
13
|
export interface HasWrapIdentifier {
|