From 2b6e4872d5b10906bcb8f570198fb5d0420eef42 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 15 Feb 2023 16:22:40 +0100 Subject: [PATCH] fiexed limit --- src/defaultHandler.ts | 19 +++++++++++++------ src/query.ts | 4 +++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index 25bc8b1..c643775 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -236,11 +236,11 @@ export class Handler { builder.addCode("select "); builder.append(joinArg(", ")(handler, q.attr)); builder.addCode(` from `); - if(q.from == null){ + if (q.from == null) { builder.addCode(" DUAL"); - }else if (q.from instanceof Table){ + } else if (q.from instanceof Table) { builder.addCode(q.from.serialize(handler)); - }else{ + } else { builder.append(q.from.serialize(handler)); } if (q.whereD) { @@ -255,9 +255,16 @@ export class Handler { builder.append(q.havingD.serialize(handler)); } } - if (q.havingD) { - builder.addCode(" limit "); - builder.addInjection(q.limitD); + if (q.limitD != null) { + if (q.limitOffsetD == null) { + builder.addCode(" limit "); + builder.addInjection(q.limitD); + } else { + builder.addCode(" limit "); + builder.addInjection(q.limitOffsetD); + builder.addCode(", "); + builder.addInjection(q.limitD); + } } /*builder.setHandler((json)=>{ diff --git a/src/query.ts b/src/query.ts index 9fd00d6..0c39120 100644 --- a/src/query.ts +++ b/src/query.ts @@ -83,8 +83,10 @@ export class selectQuery { return this; } limitD: number | null = null; - limit(i: number) { + limitOffsetD: number | null = null; + limit(i: number, offset: number = 0) { this.limitD = i; + this.limitOffsetD = offset; return this; }