From 1e396b59345056a437f94d5e0e991690a1885f03 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Fri, 24 Mar 2023 17:48:09 +0100 Subject: [PATCH] better solution --- src/defaultHandler.ts | 9 +-------- src/query.ts | 7 +------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index 114d0f9..77c88f1 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -315,7 +315,7 @@ export class Handler { }, insert: (hander: Handler, q: insertQuery): QueryBuilder => { const qb = new QueryBuilder(); - qb.addCode("INSERT INTO "); + qb.addCode("INSERT IGNORE INTO "); qb.addCode(q.attrs[0].table.serialize(hander)); qb.addCode("("); 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 = { readResponse: (resp: any) => new readResponse(resp), writeResponse: (resp: any) => new writeResponse(resp.affectedRows), diff --git a/src/query.ts b/src/query.ts index c6df5d0..cf949f6 100644 --- a/src/query.ts +++ b/src/query.ts @@ -138,12 +138,7 @@ export class insertQuery { const handler = db.getHandler(); const builder = this.serialize(handler); const s = handler.builders.query(builder); - let readResp: any; - try { - readResp = await db.query(s, printQuery); - } catch (err) { - readResp = handler.catcherrors.insert(err); - } + let readResp = await db.query(s, printQuery); return handler.responses.insertResponse(readResp); } }