adminforth 1.2.29 → 1.2.30
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.
|
@@ -257,53 +257,42 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
|
|
|
257
257
|
const tableName = resource.table;
|
|
258
258
|
const result = {};
|
|
259
259
|
await Promise.all(columns.map(async (col) => {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
const stmt = await this.client.query({
|
|
261
|
+
query: `SELECT MIN(${col.name}) as min, MAX(${col.name}) as max FROM ${tableName}`,
|
|
262
|
+
format: 'JSONEachRow',
|
|
263
|
+
});
|
|
264
|
+
const rows = await stmt.json();
|
|
265
|
+
result[col.name] = {
|
|
266
|
+
min: rows[0].min,
|
|
267
|
+
max: rows[0].max,
|
|
268
|
+
};
|
|
269
|
+
|
|
265
270
|
}))
|
|
266
271
|
return result;
|
|
267
272
|
}
|
|
268
273
|
async createRecordOriginalValues({ resource, record }: { resource: AdminForthResource, record: any }) {
|
|
269
274
|
const tableName = resource.table;
|
|
270
275
|
const columns = Object.keys(record);
|
|
271
|
-
|
|
272
|
-
// const q = `INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${columns.map((colName) => {
|
|
273
|
-
// const colType = resource.dataSourceColumns.find((col) => col.name == colName)._underlineType;
|
|
274
|
-
// if (colType.startsWith('Int') || colType.startsWith('UInt') || colType.startsWith('Float')) {
|
|
275
|
-
// return record[colName];
|
|
276
|
-
// } else {
|
|
277
|
-
// return "'"+record[colName]+"'"
|
|
278
|
-
// }
|
|
279
|
-
// }).join(', ') })`;
|
|
280
|
-
// console.log('🪲 Clickhouse Query', q) ;
|
|
281
|
-
// await this.client.command({
|
|
282
|
-
// query: q,
|
|
283
|
-
|
|
284
|
-
// });
|
|
285
|
-
|
|
286
|
-
console.log('🪲 Clickhouse Insert', record);
|
|
287
|
-
|
|
288
276
|
await this.client.insert({
|
|
289
277
|
database: this.dbName,
|
|
290
278
|
table: tableName,
|
|
291
279
|
columns: columns,
|
|
292
280
|
values: [Object.values(record)],
|
|
293
281
|
});
|
|
294
|
-
|
|
295
|
-
console.log('🪲 Clickhouse Query done');
|
|
296
|
-
|
|
297
282
|
}
|
|
298
283
|
|
|
299
284
|
async updateRecord({ resource, recordId, newValues }: { resource: AdminForthResource, recordId: any, newValues: any }) {
|
|
300
|
-
const columnsWithPlaceholders = Object.keys(newValues).map((col) =>
|
|
285
|
+
const columnsWithPlaceholders = Object.keys(newValues).map((col) => {
|
|
286
|
+
return `${col} = {${col}:${resource.dataSourceColumns.find((c) => c.name == col)._underlineType}}`
|
|
287
|
+
});
|
|
301
288
|
const values = [...Object.values(newValues), recordId];
|
|
302
289
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
290
|
+
await this.client.command(
|
|
291
|
+
{
|
|
292
|
+
query: `ALTER TABLE ${this.dbName}.${resource.table} UPDATE ${columnsWithPlaceholders.join(', ')} WHERE ${this.getPrimaryKey(resource)} = {recordId:${resource.dataSourceColumns.find((c) => c.primaryKey)._underlineType}}`,
|
|
293
|
+
query_params: { ...newValues, recordId },
|
|
294
|
+
}
|
|
295
|
+
);
|
|
307
296
|
}
|
|
308
297
|
|
|
309
298
|
async deleteRecord({ resource, recordId }: { resource: AdminForthResource, recordId: any }) {
|
|
@@ -248,11 +248,15 @@ class ClickhouseConnector extends AdminForthBaseConnector {
|
|
|
248
248
|
const tableName = resource.table;
|
|
249
249
|
const result = {};
|
|
250
250
|
yield Promise.all(columns.map((col) => __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
const stmt = yield this.client.query({
|
|
252
|
+
query: `SELECT MIN(${col.name}) as min, MAX(${col.name}) as max FROM ${tableName}`,
|
|
253
|
+
format: 'JSONEachRow',
|
|
254
|
+
});
|
|
255
|
+
const rows = yield stmt.json();
|
|
256
|
+
result[col.name] = {
|
|
257
|
+
min: rows[0].min,
|
|
258
|
+
max: rows[0].max,
|
|
259
|
+
};
|
|
256
260
|
})));
|
|
257
261
|
return result;
|
|
258
262
|
});
|
|
@@ -261,36 +265,24 @@ class ClickhouseConnector extends AdminForthBaseConnector {
|
|
|
261
265
|
return __awaiter(this, arguments, void 0, function* ({ resource, record }) {
|
|
262
266
|
const tableName = resource.table;
|
|
263
267
|
const columns = Object.keys(record);
|
|
264
|
-
// const q = `INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${columns.map((colName) => {
|
|
265
|
-
// const colType = resource.dataSourceColumns.find((col) => col.name == colName)._underlineType;
|
|
266
|
-
// if (colType.startsWith('Int') || colType.startsWith('UInt') || colType.startsWith('Float')) {
|
|
267
|
-
// return record[colName];
|
|
268
|
-
// } else {
|
|
269
|
-
// return "'"+record[colName]+"'"
|
|
270
|
-
// }
|
|
271
|
-
// }).join(', ') })`;
|
|
272
|
-
// console.log('🪲 Clickhouse Query', q) ;
|
|
273
|
-
// await this.client.command({
|
|
274
|
-
// query: q,
|
|
275
|
-
// });
|
|
276
|
-
console.log('🪲 Clickhouse Insert', record);
|
|
277
268
|
yield this.client.insert({
|
|
278
269
|
database: this.dbName,
|
|
279
270
|
table: tableName,
|
|
280
271
|
columns: columns,
|
|
281
272
|
values: [Object.values(record)],
|
|
282
273
|
});
|
|
283
|
-
console.log('🪲 Clickhouse Query done');
|
|
284
274
|
});
|
|
285
275
|
}
|
|
286
276
|
updateRecord(_a) {
|
|
287
277
|
return __awaiter(this, arguments, void 0, function* ({ resource, recordId, newValues }) {
|
|
288
|
-
const columnsWithPlaceholders = Object.keys(newValues).map((col) =>
|
|
278
|
+
const columnsWithPlaceholders = Object.keys(newValues).map((col) => {
|
|
279
|
+
return `${col} = {${col}:${resource.dataSourceColumns.find((c) => c.name == col)._underlineType}}`;
|
|
280
|
+
});
|
|
289
281
|
const values = [...Object.values(newValues), recordId];
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
282
|
+
yield this.client.command({
|
|
283
|
+
query: `ALTER TABLE ${this.dbName}.${resource.table} UPDATE ${columnsWithPlaceholders.join(', ')} WHERE ${this.getPrimaryKey(resource)} = {recordId:${resource.dataSourceColumns.find((c) => c.primaryKey)._underlineType}}`,
|
|
284
|
+
query_params: Object.assign(Object.assign({}, newValues), { recordId }),
|
|
285
|
+
});
|
|
294
286
|
});
|
|
295
287
|
}
|
|
296
288
|
deleteRecord(_a) {
|