fix(basic.gblib): Allow MERGE keyword in storage #380. @othonlima

This commit is contained in:
Rodrigo Rodriguez 2024-01-14 22:23:53 -03:00
parent aa80f485c7
commit f520c69f3f
3 changed files with 20 additions and 7 deletions

View file

@ -281,9 +281,6 @@ export class GBVMService extends GBService {
obj.type.key = "BIGINT"
associations.push({ from: tableName, to: obj.type.name });
}
if (key.toLowerCase() === 'id') {
obj['primaryKey'] = true;
}
});
// Cutom connection for TABLE.
@ -672,7 +669,6 @@ export class GBVMService extends GBService {
Fs.writeFileSync(tablesFile, JSON.stringify(task.tables));
}
}
}
@ -764,6 +760,15 @@ export class GBVMService extends GBService {
let required = line.indexOf('*') !== -1;
let unique = /\bunique\b/gi.test(line);
let primaryKey = /\bkey\b/gi.test(line);
let autoIncrement = /\bauto\b/gi.test(line);
if (primaryKey){
autoIncrement = true;
unique = true;
required = true;
}
line = line.replace('*', '');
const fieldRegExp = /^\s*(\w+)\s*(\w+)(?:\((.*)\))?/gim;
@ -772,7 +777,9 @@ export class GBVMService extends GBService {
const name = reg[1];
const t = reg[2];
let definition = { allowNull: !required, unique: unique };
let definition = { allowNull: !required,
unique: unique, primaryKey: primaryKey,
autoIncrement: autoIncrement };
definition['type'] = t;
if (reg[3]) {

View file

@ -1192,7 +1192,7 @@ export class KeywordsExpressions {
// Checks if it is a collection or series of params.
return `
if (${fields[0]}[0]){
if (Array.isArray(${fields[0]})){
await sys.saveToStorageBatch({pid: pid, table: ${table}, rows:${fields[0]} })
}else{
await sys.saveToStorage({pid: pid, table: ${table}, fieldsValues: [${fieldsAsText}], fieldsNames: [${fieldsNames}] })

View file

@ -737,6 +737,12 @@ export class SystemKeywords {
const { min } = await DialogKeywords.getProcessInfo(pid);
GBLog.info(`BASIC: Saving batch to storage '${table}' (SAVE).`);
if (rows.length === 0)
{
return;
}
const definition = this.getTableFromName(table, min);
const rowsDest = [];
@ -750,7 +756,7 @@ export class SystemKeywords {
i++;
});
rowsDest.push(dst);
});
});
await retry(
async (bail) => {