Merge pull request 'better solution' (#19) from dev into main
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

Reviewed-on: #19
This commit is contained in:
jusax23 2023-03-24 17:49:11 +01:00
commit 21b2bec2c4
2 changed files with 2 additions and 14 deletions

View file

@ -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 INTO "); qb.addCode("INSERT IGNORE 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,13 +604,6 @@ 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),

View file

@ -138,12 +138,7 @@ 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: any; let readResp = await db.query(s, printQuery);
try {
readResp = await db.query(s, printQuery);
} catch (err) {
readResp = handler.catcherrors.insert(err);
}
return handler.responses.insertResponse(readResp); return handler.responses.insertResponse(readResp);
} }
} }