Compare commits
No commits in common. "21b2bec2c4d19a0b6317f0ba3479cb0b0abb2552" and "57544dffd2541c58269490339ec21ae4f597f884" have entirely different histories.
21b2bec2c4
...
57544dffd2
2 changed files with 14 additions and 2 deletions
|
@ -315,7 +315,7 @@ export class Handler {
|
||||||
},
|
},
|
||||||
insert: (hander: Handler, q: insertQuery): QueryBuilder => {
|
insert: (hander: Handler, q: insertQuery): QueryBuilder => {
|
||||||
const qb = new QueryBuilder();
|
const qb = new QueryBuilder();
|
||||||
qb.addCode("INSERT IGNORE INTO ");
|
qb.addCode("INSERT INTO ");
|
||||||
qb.addCode(q.attrs[0].table.serialize(hander));
|
qb.addCode(q.attrs[0].table.serialize(hander));
|
||||||
qb.addCode("(");
|
qb.addCode("(");
|
||||||
qb.addCodeCommaSeperated(q.attrs.map(a => a.serialize(hander)));
|
qb.addCodeCommaSeperated(q.attrs.map(a => a.serialize(hander)));
|
||||||
|
@ -604,6 +604,13 @@ export class Handler {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catcherrors = {
|
||||||
|
insert: (err: any) => {
|
||||||
|
if(err?.code == "ER_DUP_ENTRY") return {affectedRows: 0, insertId: -1};
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
responses = {
|
responses = {
|
||||||
readResponse: (resp: any) => new readResponse(resp),
|
readResponse: (resp: any) => new readResponse(resp),
|
||||||
writeResponse: (resp: any) => new writeResponse(resp.affectedRows),
|
writeResponse: (resp: any) => new writeResponse(resp.affectedRows),
|
||||||
|
|
|
@ -138,7 +138,12 @@ export class insertQuery {
|
||||||
const handler = db.getHandler();
|
const handler = db.getHandler();
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
let readResp = await db.query(s, printQuery);
|
let readResp: any;
|
||||||
|
try {
|
||||||
|
readResp = await db.query(s, printQuery);
|
||||||
|
} catch (err) {
|
||||||
|
readResp = handler.catcherrors.insert(err);
|
||||||
|
}
|
||||||
return handler.responses.insertResponse(readResp);
|
return handler.responses.insertResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue