new(basic.gblib): Databases. #392 @othonlima.
This commit is contained in:
parent
6a8beecc14
commit
2cd4d64bd1
2 changed files with 33 additions and 14 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 = {};
|
||||||
|
|
||||||
|
@ -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.`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue