remult 0.22.6-exp.1 → 0.22.6-exp.2
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/remult-duckdb.js +7 -12
- package/esm/remult-sqlite-core.js +33 -5
- package/esm/server/get-remult-admin-html.js +1 -1
- package/esm/server/remult-admin.js +27 -21
- package/esm/server/remult-api-server.js +4 -5
- package/esm/src/data-api.js +4 -2
- package/package.json +1 -1
- package/remult-duckdb.d.ts +1 -1
- package/remult-duckdb.js +7 -12
- 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-admin.js +17 -11
- package/server/remult-api-server.d.ts +1 -1
- package/server/remult-api-server.js +8 -8
- package/src/data-api.js +4 -2
package/esm/remult-duckdb.js
CHANGED
|
@@ -33,13 +33,13 @@ export class DuckDBDataProvider extends SqliteCoreDataProvider {
|
|
|
33
33
|
.join(',')})`;
|
|
34
34
|
sql +=
|
|
35
35
|
'create table if not exists ' + e.$entityName + ' (' + result + '\r\n)';
|
|
36
|
-
return sql;
|
|
36
|
+
return [sql];
|
|
37
37
|
}
|
|
38
38
|
addColumnSqlSyntax(x, dbName, isAlterColumn) {
|
|
39
39
|
let result = dbName;
|
|
40
40
|
var allowNull = x.allowNull;
|
|
41
|
-
if (allowNull && isAlterColumn) {
|
|
42
|
-
allowNull =
|
|
41
|
+
if (!allowNull && isAlterColumn) {
|
|
42
|
+
allowNull = true;
|
|
43
43
|
console.log('DuckDB does not support altering columns to allow null on existing tables');
|
|
44
44
|
}
|
|
45
45
|
if (x.valueType == Number) {
|
|
@@ -49,7 +49,7 @@ export class DuckDBDataProvider extends SqliteCoreDataProvider {
|
|
|
49
49
|
result +=
|
|
50
50
|
' ' +
|
|
51
51
|
x.valueConverter.fieldTypeInDb +
|
|
52
|
-
(
|
|
52
|
+
(allowNull ? '' : ' default 0 not null');
|
|
53
53
|
}
|
|
54
54
|
else if (x.valueType == Date) {
|
|
55
55
|
if (!x.valueConverter.fieldTypeInDb)
|
|
@@ -61,20 +61,15 @@ export class DuckDBDataProvider extends SqliteCoreDataProvider {
|
|
|
61
61
|
result += ' ' + x.valueConverter.fieldTypeInDb;
|
|
62
62
|
}
|
|
63
63
|
else if (x.valueType == Boolean)
|
|
64
|
-
result +=
|
|
65
|
-
' boolean' +
|
|
66
|
-
(x.allowNull || isAlterColumn ? '' : ' default false not null');
|
|
64
|
+
result += ' boolean' + (allowNull ? '' : ' default false not null');
|
|
67
65
|
else if (x.valueConverter.fieldTypeInDb) {
|
|
68
66
|
result += ' ' + x.valueConverter.fieldTypeInDb;
|
|
69
|
-
if (!
|
|
70
|
-
x.valueConverter.fieldTypeInDb == 'integer') {
|
|
67
|
+
if (!allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
71
68
|
result += ' default 0 not null';
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
else
|
|
75
|
-
result +=
|
|
76
|
-
' varchar' +
|
|
77
|
-
(x.allowNull || isAlterColumn ? '' : " default '' not null");
|
|
72
|
+
result += ' varchar' + (allowNull ? '' : " default '' not null");
|
|
78
73
|
return result;
|
|
79
74
|
}
|
|
80
75
|
}
|
|
@@ -21,7 +21,7 @@ export class SqliteCoreDataProvider {
|
|
|
21
21
|
let self = this;
|
|
22
22
|
return {
|
|
23
23
|
createTable: async (entity) => {
|
|
24
|
-
|
|
24
|
+
await (await self.getCreateTableSql(entity)).map(builder.addSql);
|
|
25
25
|
},
|
|
26
26
|
addColumn: async (entity, field) => {
|
|
27
27
|
let e = await dbNamesOf(entity, this.wrapIdentifier);
|
|
@@ -45,6 +45,27 @@ export class SqliteCoreDataProvider {
|
|
|
45
45
|
async ensureSchema(entities) {
|
|
46
46
|
for (const entity of entities) {
|
|
47
47
|
await this.createTableIfNotExist(entity);
|
|
48
|
+
await this.verifyAllColumns(entity);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async verifyAllColumns(entity) {
|
|
52
|
+
try {
|
|
53
|
+
let cmd = this.createCommand();
|
|
54
|
+
let e = await dbNamesOf(entity, this.wrapIdentifier);
|
|
55
|
+
let cols = (await cmd.execute(`PRAGMA table_info(${e.$entityName})`)).rows.map((x) => this.wrapIdentifier(x.name.toLocaleLowerCase()));
|
|
56
|
+
for (const col of entity.fields) {
|
|
57
|
+
if (!shouldNotCreateField(col, e)) {
|
|
58
|
+
let colName = e.$dbNameOf(col).toLocaleLowerCase();
|
|
59
|
+
if (!cols.includes(colName)) {
|
|
60
|
+
let sql = `ALTER table ${e.$entityName} ` +
|
|
61
|
+
`add column ${this.addColumnSqlSyntax(col, e.$dbNameOf(col), true)}`;
|
|
62
|
+
await this.createCommand().execute(sql);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.error(err);
|
|
48
69
|
}
|
|
49
70
|
}
|
|
50
71
|
async dropTable(entity) {
|
|
@@ -73,9 +94,9 @@ export class SqliteCoreDataProvider {
|
|
|
73
94
|
}
|
|
74
95
|
async createTableIfNotExist(entity) {
|
|
75
96
|
let sql = await this.getCreateTableSql(entity);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
97
|
+
for (const element of sql) {
|
|
98
|
+
await this.createCommand().execute(element);
|
|
99
|
+
}
|
|
79
100
|
}
|
|
80
101
|
supportsJsonColumnType;
|
|
81
102
|
async getCreateTableSql(entity) {
|
|
@@ -99,7 +120,14 @@ export class SqliteCoreDataProvider {
|
|
|
99
120
|
}
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
|
-
let sql =
|
|
123
|
+
let sql = [
|
|
124
|
+
'create table if not exists ' + e.$entityName + ' (' + result + '\r\n)',
|
|
125
|
+
];
|
|
126
|
+
if (entity.idMetadata.fields.length > 1) {
|
|
127
|
+
sql.push(`create unique index ${this.wrapIdentifier(entity.dbName + '_primary_key')} on ${e.$entityName} (${entity.idMetadata.fields
|
|
128
|
+
.map((x) => e.$dbNameOf(x))
|
|
129
|
+
.join(',')})`);
|
|
130
|
+
}
|
|
103
131
|
return sql;
|
|
104
132
|
}
|
|
105
133
|
wrapIdentifier(name) {
|