This commit is contained in:
parent
d69b204c4c
commit
a12f629690
|
@ -5,6 +5,38 @@ const EnumFactory = require('loopback-connector-mysql').EnumFactory;
|
||||||
const Transaction = require('loopback-connector').Transaction;
|
const Transaction = require('loopback-connector').Transaction;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const limitSet = new Set([
|
||||||
|
'save',
|
||||||
|
'updateOrCreate',
|
||||||
|
'replaceOrCreate',
|
||||||
|
'replaceById',
|
||||||
|
'update'
|
||||||
|
]);
|
||||||
|
|
||||||
|
const opOpts = {
|
||||||
|
update: [
|
||||||
|
'update',
|
||||||
|
'replaceById',
|
||||||
|
// |insert
|
||||||
|
'save',
|
||||||
|
'updateOrCreate',
|
||||||
|
'replaceOrCreate'
|
||||||
|
],
|
||||||
|
delete: [
|
||||||
|
'destroy',
|
||||||
|
'destroyAll'
|
||||||
|
],
|
||||||
|
insert: [
|
||||||
|
'create'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const opMap = new Map();
|
||||||
|
for (const op in opOpts) {
|
||||||
|
for (const met of opOpts[op])
|
||||||
|
opMap.set(met, op);
|
||||||
|
}
|
||||||
|
|
||||||
class VnMySQL extends MySQL {
|
class VnMySQL extends MySQL {
|
||||||
/**
|
/**
|
||||||
* Promisified version of execute().
|
* Promisified version of execute().
|
||||||
|
@ -299,41 +331,8 @@ class VnMySQL extends MySQL {
|
||||||
const data = ctx.data;
|
const data = ctx.data;
|
||||||
const idName = this.idName(model);
|
const idName = this.idName(model);
|
||||||
|
|
||||||
const limitSet = new Set([
|
|
||||||
'save',
|
|
||||||
'updateOrCreate',
|
|
||||||
'replaceOrCreate',
|
|
||||||
'replaceById',
|
|
||||||
'updateAttributes',
|
|
||||||
'update'
|
|
||||||
]);
|
|
||||||
|
|
||||||
const limit = limitSet.has(method);
|
const limit = limitSet.has(method);
|
||||||
|
|
||||||
const opOpts = {
|
|
||||||
update: [
|
|
||||||
'update',
|
|
||||||
'replaceById',
|
|
||||||
'updateAttributes',
|
|
||||||
// |insert
|
|
||||||
'save',
|
|
||||||
'updateOrCreate',
|
|
||||||
'replaceOrCreate'
|
|
||||||
],
|
|
||||||
delete: [
|
|
||||||
'destroy',
|
|
||||||
'destroyAll'
|
|
||||||
],
|
|
||||||
insert: [
|
|
||||||
'create'
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
const opMap = new Map();
|
|
||||||
for (const op in opOpts) {
|
|
||||||
for (const met of opOpts[op])
|
|
||||||
opMap.set(met, op);
|
|
||||||
}
|
|
||||||
const op = opMap.get(method);
|
const op = opMap.get(method);
|
||||||
|
|
||||||
if (!where) {
|
if (!where) {
|
||||||
|
@ -356,8 +355,7 @@ class VnMySQL extends MySQL {
|
||||||
|
|
||||||
const res = await new Promise(resolve => {
|
const res = await new Promise(resolve => {
|
||||||
const fnArgs = args.slice(0, -2);
|
const fnArgs = args.slice(0, -2);
|
||||||
fnArgs.push(opts);
|
fnArgs.push(opts, (...args) => resolve(args));
|
||||||
fnArgs.push((...args) => resolve(args));
|
|
||||||
super[method].apply(this, fnArgs);
|
super[method].apply(this, fnArgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -514,7 +512,7 @@ class VnMySQL extends MySQL {
|
||||||
// Delete unchanged properties
|
// Delete unchanged properties
|
||||||
if (oldI) {
|
if (oldI) {
|
||||||
Object.keys(oldI).forEach(prop => {
|
Object.keys(oldI).forEach(prop => {
|
||||||
if (newI[prop] == oldI[prop]) {
|
if (newI[prop] === oldI[prop]) {
|
||||||
delete newI[prop];
|
delete newI[prop];
|
||||||
delete oldI[prop];
|
delete oldI[prop];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue