From f520c69f3fc825703b241754c5a4c33edac900e1 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 14 Jan 2024 22:23:53 -0300 Subject: [PATCH] fix(basic.gblib): Allow MERGE keyword in storage #380. @othonlima --- packages/basic.gblib/services/GBVMService.ts | 17 ++++++++++++----- .../basic.gblib/services/KeywordsExpressions.ts | 2 +- packages/basic.gblib/services/SystemKeywords.ts | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index c1f3847b..1b78d2d2 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -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]) { diff --git a/packages/basic.gblib/services/KeywordsExpressions.ts b/packages/basic.gblib/services/KeywordsExpressions.ts index 69b6a5c1..4f026d0f 100644 --- a/packages/basic.gblib/services/KeywordsExpressions.ts +++ b/packages/basic.gblib/services/KeywordsExpressions.ts @@ -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}] }) diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index 52b9b4ff..c86eebc9 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -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) => {