mirror of
https://github.com/Fabio286/antares.git
synced 2025-04-12 17:31:11 +02:00
perf(core): bulk inserts support
This commit is contained in:
parent
9a190854fe
commit
b0576acdf6
@ -189,13 +189,13 @@ export default (connections) => {
|
|||||||
insertObj[key] = escapedParam;
|
insertObj[key] = escapedParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < params.repeat; i++) {
|
const rows = new Array(+params.repeat).fill(insertObj);
|
||||||
await connections[params.uid]
|
|
||||||
.schema(params.schema)
|
await connections[params.uid]
|
||||||
.into(params.table)
|
.schema(params.schema)
|
||||||
.insert(insertObj)
|
.into(params.table)
|
||||||
.run();
|
.insert(rows)
|
||||||
}
|
.run();
|
||||||
|
|
||||||
return { status: 'success' };
|
return { status: 'success' };
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export class AntaresCore {
|
|||||||
limit: [],
|
limit: [],
|
||||||
join: [],
|
join: [],
|
||||||
update: [],
|
update: [],
|
||||||
insert: {},
|
insert: [],
|
||||||
delete: false
|
delete: false
|
||||||
};
|
};
|
||||||
this._query = Object.assign({}, this._queryDefaults);
|
this._query = Object.assign({}, this._queryDefaults);
|
||||||
@ -120,12 +120,12 @@ export class AntaresCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} obj field: value
|
* @param {Array} arr Array of row objects
|
||||||
* @returns
|
* @returns
|
||||||
* @memberof AntaresCore
|
* @memberof AntaresCore
|
||||||
*/
|
*/
|
||||||
insert (obj) {
|
insert (arr) {
|
||||||
this._query.insert = { ...this._query.insert, ...obj };
|
this._query.insert = [...this._query.insert, ...arr];
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1157,18 +1157,11 @@ export class MySQLClient extends AntaresCore {
|
|||||||
// INSERT
|
// INSERT
|
||||||
let insertRaw = '';
|
let insertRaw = '';
|
||||||
|
|
||||||
if (Object.keys(this._query.insert).length) {
|
if (this._query.insert.length) {
|
||||||
const fieldsList = [];
|
const fieldsList = Object.keys(this._query.insert[0]);
|
||||||
const valueList = [];
|
const rowsList = this._query.insert.map(el => `(${Object.values(el).join(', ')})`);
|
||||||
const fields = this._query.insert;
|
|
||||||
|
|
||||||
for (const key in fields) {
|
insertRaw = `(${fieldsList.join(', ')}) VALUES ${rowsList.join(', ')} `;
|
||||||
if (fields[key] === null) continue;
|
|
||||||
fieldsList.push(key);
|
|
||||||
valueList.push(fields[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
insertRaw = `(${fieldsList.join(', ')}) VALUES (${valueList.join(', ')}) `;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GROUP BY
|
// GROUP BY
|
||||||
|
@ -157,6 +157,8 @@ export default {
|
|||||||
nInserts (val) {
|
nInserts (val) {
|
||||||
if (!val || val < 1)
|
if (!val || val < 1)
|
||||||
this.nInserts = 1;
|
this.nInserts = 1;
|
||||||
|
if (!val || val > 1000)
|
||||||
|
this.nInserts = 1000;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user