fix(basic.gblib): Allow MERGE keyword in storage #380. @othonlima
This commit is contained in:
parent
42a9a8c402
commit
0c9d7a40ae
2 changed files with 33 additions and 10 deletions
|
@ -213,7 +213,7 @@ export class GBVMService extends GBService {
|
||||||
case 'key':
|
case 'key':
|
||||||
return { key: 'STRING' }; // Assuming key is a string data type
|
return { key: 'STRING' }; // Assuming key is a string data type
|
||||||
case 'number':
|
case 'number':
|
||||||
return { key: 'INTEGER' };
|
return { key: 'BIGINT' };
|
||||||
case 'integer':
|
case 'integer':
|
||||||
return { key: 'INTEGER' };
|
return { key: 'INTEGER' };
|
||||||
case 'double':
|
case 'double':
|
||||||
|
@ -295,9 +295,7 @@ export class GBVMService extends GBService {
|
||||||
const to = minBoot.core.sequelize.models[e.to];
|
const to = minBoot.core.sequelize.models[e.to];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
from.hasMany(to);
|
to.hasMany(from);
|
||||||
to.belongsTo(from);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`BASIC: Invalid relationship in ${mainName}: from ${e.from} to ${e.to} (${min.botId})... ${error.message}`);
|
throw new Error(`BASIC: Invalid relationship in ${mainName}: from ${e.from} to ${e.to} (${min.botId})... ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -660,12 +660,37 @@ export class SystemKeywords {
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
const definition = minBoot.core.sequelize.models[table];
|
const definition = minBoot.core.sequelize.models[table];
|
||||||
|
|
||||||
|
let out = [];
|
||||||
|
let src = {}, dst = {};
|
||||||
|
|
||||||
|
// Flattern JSON to a table.
|
||||||
|
|
||||||
|
src = this.flattenJSON(fieldsValues, {}, '_')
|
||||||
|
|
||||||
|
// Uppercases fields.
|
||||||
|
let i = 0;
|
||||||
|
Object.keys(src).forEach(fieldSrc => {
|
||||||
|
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
||||||
|
|
||||||
|
dst[field] = src[fieldSrc];
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
|
||||||
|
return await definition.create(dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async saveToStorageWithJSON({ pid, table, fieldsValues, fieldsNames }): Promise<any> {
|
||||||
|
|
||||||
|
GBLog.info(`BASIC: Saving to storage '${table}' (SAVE).`);
|
||||||
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
|
const definition = minBoot.core.sequelize.models[table];
|
||||||
|
|
||||||
let out = [];
|
let out = [];
|
||||||
let data = {}, data2 = {};
|
let data = {}, data2 = {};
|
||||||
|
|
||||||
// Flattern JSON to a table.
|
// Flattern JSON to a table.
|
||||||
|
|
||||||
data = this.flattenJSON(fieldsValues, {}, '')
|
data = this.flattenJSON(fieldsValues, {}, '_')
|
||||||
|
|
||||||
// Uppercases fields.
|
// Uppercases fields.
|
||||||
|
|
||||||
|
@ -1993,7 +2018,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
||||||
row = this.flattenJSON(row, {}, '')
|
row = this.flattenJSON(row, {}, '_')
|
||||||
for (let j = 0; j < header.length; j++) {
|
for (let j = 0; j < header.length; j++) {
|
||||||
|
|
||||||
const columnName = header[j];
|
const columnName = header[j];
|
||||||
|
@ -2023,10 +2048,10 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Check if is a tree or flat object.
|
// Check if is a tree or flat object.
|
||||||
|
|
||||||
const hasSubObject = (products) => {
|
const hasSubObject = (t) => {
|
||||||
for (var key in products) {
|
for (var key in t) {
|
||||||
if (!products.hasOwnProperty(key)) continue;
|
if (!t.hasOwnProperty(key)) continue;
|
||||||
if (typeof products[key] === "object") return true;
|
if (typeof t[key] === "object") return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue