fix(basic.gblib): Allow MERGE keyword in storage #380.
This commit is contained in:
parent
6e1c01e6fe
commit
1dd7b2aa99
2 changed files with 37 additions and 8 deletions
|
@ -53,7 +53,7 @@ import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
|||
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
||||
import { SystemKeywords } from './SystemKeywords.js';
|
||||
import lineReplace from 'line-replace';
|
||||
import { Sequelize, DataTypes } from '@sequelize/core';
|
||||
import { Sequelize, DataTypes, QueryTypes } from '@sequelize/core';
|
||||
import { table } from 'console';
|
||||
|
||||
/**
|
||||
|
@ -227,6 +227,13 @@ export class GBVMService extends GBService {
|
|||
|
||||
const associations = [];
|
||||
|
||||
const tables = await min.core.sequelize.query(`SELECT table_name, table_schema
|
||||
FROM information_schema.tables
|
||||
WHERE table_type = 'BASE TABLE'
|
||||
ORDER BY table_name ASC`, {
|
||||
type: QueryTypes.RAW
|
||||
})
|
||||
|
||||
tableDef.forEach(t => {
|
||||
Object.keys(t.fields).forEach(key => {
|
||||
let obj = t.fields[key];
|
||||
|
@ -240,7 +247,7 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
});
|
||||
|
||||
// Only syncs if there is any difference.
|
||||
// Field checking, syncs if there is any difference.
|
||||
|
||||
const model = minBoot.core.sequelize.models[t.name];
|
||||
if (model) {
|
||||
|
@ -267,15 +274,32 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
|
||||
minBoot.core.sequelize.define(t.name, t.fields);
|
||||
|
||||
// New table checking, if needs sync.
|
||||
let found = false;
|
||||
tables[0].forEach ((storageTable)=>{
|
||||
if (storageTable['table_name'] === t.name)
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
|
||||
sync = sync? sync: !found;
|
||||
|
||||
});
|
||||
|
||||
associations.forEach(e => {
|
||||
const from = minBoot.core.sequelize.models[e.from];
|
||||
const to = minBoot.core.sequelize.models[e.to];
|
||||
|
||||
try {
|
||||
from.hasMany(to);
|
||||
to.belongsTo(from);
|
||||
|
||||
} catch (error) {
|
||||
throw new Error(`BASIC: Invalid relationship in ${mainName}: from ${e.from} to ${e.to} (${min.botId})... ${error.message}`);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (sync) {
|
||||
|
|
|
@ -663,6 +663,8 @@ export class SystemKeywords {
|
|||
let data = {};
|
||||
let index = 0;
|
||||
|
||||
data = this.flattenJSON(fieldsValues,{}, '')
|
||||
|
||||
fieldsNames.forEach(field => {
|
||||
field = field.charAt(0).toUpperCase() + field.slice(1);
|
||||
data[field] = fieldsValues[index++];
|
||||
|
@ -1504,12 +1506,12 @@ export class SystemKeywords {
|
|||
return GBAdminService.getRndPassword();
|
||||
}
|
||||
|
||||
private flattenJSON(obj, res, extraKey) {
|
||||
private flattenJSON(obj, res, extraKey, hierarchy=false) {
|
||||
for (let key in obj) {
|
||||
if (typeof obj[key] !== 'object') {
|
||||
res[extraKey + key] = obj[key];
|
||||
} else {
|
||||
this.flattenJSON(obj[key], res, `${extraKey}${key}.`);
|
||||
this.flattenJSON(obj[key], res, hierarchy?`${extraKey}${key}.`:'');
|
||||
};
|
||||
};
|
||||
return res;
|
||||
|
@ -2112,7 +2114,7 @@ export class SystemKeywords {
|
|||
|
||||
// Choose data sources based on file type (HTML Table, data variable or sheet file)
|
||||
|
||||
let storage = file.indexOf('.xlsx') !== -1;
|
||||
let storage = file.indexOf('.xlsx') === -1;
|
||||
let results;
|
||||
let header = [], rows = [];
|
||||
const minBoot = GBServer.globals.minBoot;
|
||||
|
@ -2120,6 +2122,9 @@ export class SystemKeywords {
|
|||
|
||||
if (storage) {
|
||||
t = minBoot.core.sequelize.models[file];
|
||||
if (!t) {
|
||||
throw new Error(`TABLE ${file} not found. Check TABLE keywords.`);
|
||||
}
|
||||
rows = await t.findAll({});
|
||||
header = rows['dataNames'];
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue