fix(basic.gblib): Allow MERGE keyword in storage #380. @othonlima
This commit is contained in:
parent
1447f31fb6
commit
f3205594f0
2 changed files with 42 additions and 27 deletions
|
@ -96,6 +96,10 @@ export class GuaribasConversation extends Model<GuaribasConversation> {
|
|||
@Column(DataType.DATE)
|
||||
declare createdAt: Date;
|
||||
|
||||
@Column(DataType.DATE)
|
||||
@UpdatedAt
|
||||
declare updatedAt: Date;
|
||||
|
||||
@Column(DataType.STRING(255))
|
||||
declare text: string;
|
||||
|
||||
|
|
|
@ -1934,6 +1934,7 @@ export class SystemKeywords {
|
|||
const minBoot = GBServer.globals.minBoot;
|
||||
let t;
|
||||
let fieldsNames = [];
|
||||
let fieldsSizes = [];
|
||||
|
||||
if (storage) {
|
||||
t = minBoot.core.sequelize.models[file];
|
||||
|
@ -1945,6 +1946,10 @@ export class SystemKeywords {
|
|||
fieldsNames.push(e);
|
||||
})
|
||||
|
||||
Object.keys(t.fieldRawAttributesMap).forEach(e => {
|
||||
fieldsSizes.push(t.fieldRawAttributesMap[e].size);
|
||||
})
|
||||
|
||||
rows = await t.findAll({});
|
||||
if (rows.length > 0) {
|
||||
header = Object.keys(rows[0].dataValues)
|
||||
|
@ -2011,7 +2016,7 @@ export class SystemKeywords {
|
|||
|
||||
// Scans all items in incoming data.
|
||||
|
||||
for (let i = 1; i < data.length; i++) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
|
||||
// Scans all sheet lines and compare keys.
|
||||
|
||||
|
@ -2041,16 +2046,17 @@ export class SystemKeywords {
|
|||
}
|
||||
|
||||
if (found) {
|
||||
|
||||
let merge = false;
|
||||
for (let j = 0; j < header.length; j++) {
|
||||
|
||||
const columnName = header[j];
|
||||
|
||||
let columnNameFound = false;
|
||||
|
||||
let value;
|
||||
Object.keys(row).forEach(e => {
|
||||
if (columnName.toLowerCase().indexOf(e.toLowerCase()) !== -1) {
|
||||
value = row[e];
|
||||
columnNameFound = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2063,7 +2069,7 @@ export class SystemKeywords {
|
|||
}
|
||||
});
|
||||
|
||||
if (value != valueFound) {
|
||||
if (value != valueFound && columnNameFound) {
|
||||
|
||||
if (storage) {
|
||||
|
||||
|
@ -2080,14 +2086,13 @@ export class SystemKeywords {
|
|||
|
||||
await this.set({ pid, handle: null, file, address, value });
|
||||
}
|
||||
merges++;
|
||||
}
|
||||
else
|
||||
{
|
||||
skipped++;
|
||||
merge = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
merge ? merges++ : skipped++;
|
||||
|
||||
} else {
|
||||
|
||||
let fieldsValues = [];
|
||||
|
@ -2096,7 +2101,13 @@ export class SystemKeywords {
|
|||
let add = false;
|
||||
Object.keys(row).forEach(p => {
|
||||
if (fieldsNames[j].toLowerCase().indexOf(p.toLowerCase()) !== -1) {
|
||||
fieldsValues.push(row[p]);
|
||||
|
||||
let value = row[p];
|
||||
if (typeof (value) === 'string') {
|
||||
value = value.substr(0, fieldsSizes[j]);
|
||||
}
|
||||
|
||||
fieldsValues.push(value);
|
||||
add = true;
|
||||
}
|
||||
});
|
||||
|
@ -2120,7 +2131,7 @@ export class SystemKeywords {
|
|||
GBLog.info(`BASIC: MERGE ran but updated zero rows.`);
|
||||
return null;
|
||||
} else {
|
||||
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}.`);
|
||||
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}).`);
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue