new(basic.gblib): Databases. #392 @othonlima.

This commit is contained in:
Rodrigo Rodriguez 2023-11-29 00:58:44 -03:00
parent 6a8beecc14
commit 2cd4d64bd1
2 changed files with 33 additions and 14 deletions

View file

@ -340,6 +340,7 @@ export class GBVMService extends GBService {
minBoot.core.sequelize.define(t.name, t.fields); minBoot.core.sequelize.define(t.name, t.fields);
// New table checking, if needs sync. // New table checking, if needs sync.
let found = false; let found = false;
tables[0].forEach((storageTable) => { tables[0].forEach((storageTable) => {
if (storageTable['table_name'] === t.name) { if (storageTable['table_name'] === t.name) {
@ -678,6 +679,7 @@ export class GBVMService extends GBService {
let properties = []; let properties = [];
let description; let description;
let table = null; // Used for TABLE keyword. let table = null; // Used for TABLE keyword.
let connection = null;
const tasks = []; const tasks = [];
let fields = {}; let fields = {};
let tables = []; let tables = [];
@ -716,12 +718,13 @@ export class GBVMService extends GBService {
if (endTableReg && table) { if (endTableReg && table) {
tables.push({ tables.push({
name: table, fields: fields name: table, fields: fields, connection:connection
}); });
fields = {}; fields = {};
table = null; table = null;
connection = null;
emmit = false; emmit = false;
} }
@ -733,10 +736,11 @@ export class GBVMService extends GBService {
emmit = false; emmit = false;
} }
const tableKeyword = /^\s*TABLE\s*(.*)/gim; const tableKeyword = /^\s*TABLE\s*(.*)\s*ON\s*(.*)/gim;
let tableReg = tableKeyword.exec(line); let tableReg = tableKeyword.exec(line);
if (tableReg && !table) { if (tableReg && !table) {
table = tableReg[1]; table = tableReg[1];
connection= tableReg[2];
emmit = false; emmit = false;
} }

View file

@ -655,10 +655,11 @@ export class SystemKeywords {
* *
*/ */
public async saveToStorage({ pid, table, fieldsValues, fieldsNames }): Promise<any> { public async saveToStorage({ pid, table, fieldsValues, fieldsNames }): Promise<any> {
const { min } = await DialogKeywords.getProcessInfo(pid);
GBLog.info(`BASIC: Saving to storage '${table}' (SAVE).`); GBLog.info(`BASIC: Saving to storage '${table}' (SAVE).`);
const minBoot = GBServer.globals.minBoot as any; const minBoot = GBServer.globals.minBoot as any;
const definition = minBoot.core.sequelize.models[table];
const definition = this.getTableFromName(table, min);
let dst = {}; let dst = {};
@ -1612,23 +1613,23 @@ export class SystemKeywords {
let res = JSON.parse(await result.text()); let res = JSON.parse(await result.text());
function process(key,value,o) { function process(key, value, o) {
if (value === '0000-00-00'){ if (value === '0000-00-00') {
o[key] = '01-01-1970' o[key] = '01-01-1970'
} }
} }
function traverse(o,func) { function traverse(o, func) {
for (var i in o) { for (var i in o) {
func.apply(this,[i,o[i], o]); func.apply(this, [i, o[i], o]);
if (o[i] !== null && typeof(o[i])=="object") { if (o[i] !== null && typeof (o[i]) == "object") {
traverse(o[i],func); traverse(o[i], func);
} }
} }
} }
traverse(res,process); traverse(res, process);
if (pageMode === "auto") { if (pageMode === "auto") {
@ -1913,6 +1914,18 @@ export class SystemKeywords {
return letters; return letters;
} }
private getTableFromName(file, min){
const minBoot = GBServer.globals.minBoot;
const parts = file.split('.');
const con = min[parts[0]];
if (con) {
return con.models[parts[1]];
} else {
return minBoot.core.sequelize.models[file];
}
}
/** /**
* Merges a multi-value with a tabular file using BY field as key. * Merges a multi-value with a tabular file using BY field as key.
* *
@ -1957,7 +1970,9 @@ export class SystemKeywords {
let fieldsSizes = []; let fieldsSizes = [];
if (storage) { if (storage) {
t = minBoot.core.sequelize.models[file];
t = this.getTableFromName(file, min);
if (!t) { if (!t) {
throw new Error(`TABLE ${file} not found. Check TABLE keywords.`); throw new Error(`TABLE ${file} not found. Check TABLE keywords.`);
} }