@@ -98,7 +98,15 @@ export class AccessTokenModel {
98
98
this . hasSelect = false
99
99
}
100
100
101
- static select ( params : ( keyof AccessTokenType ) [ ] | RawBuilder < string > ) : AccessTokenModel {
101
+ select ( params : ( keyof AccessTokenType ) [ ] | RawBuilder < string > | string ) : AccessTokenModel {
102
+ this . selectFromQuery = this . selectFromQuery . select ( params )
103
+
104
+ this . hasSelect = true
105
+
106
+ return this
107
+ }
108
+
109
+ static select ( params : ( keyof AccessTokenType ) [ ] | RawBuilder < string > | string ) : AccessTokenModel {
102
110
const instance = new AccessTokenModel ( null )
103
111
104
112
// Initialize a query with the table name and selected fields
@@ -502,6 +510,47 @@ export class AccessTokenModel {
502
510
return this
503
511
}
504
512
513
+ static where ( ...args : ( string | number | boolean | undefined | null ) [ ] ) : AccessTokenModel {
514
+ let column : any
515
+ let operator : any
516
+ let value : any
517
+
518
+ const instance = new AccessTokenModel ( null )
519
+
520
+ if ( args . length === 2 ) {
521
+ [ column , value ] = args
522
+ operator = '='
523
+ }
524
+ else if ( args . length === 3 ) {
525
+ [ column , operator , value ] = args
526
+ }
527
+ else {
528
+ throw new HttpError ( 500 , 'Invalid number of arguments' )
529
+ }
530
+
531
+ instance . selectFromQuery = instance . selectFromQuery . where ( column , operator , value )
532
+
533
+ instance . updateFromQuery = instance . updateFromQuery . where ( column , operator , value )
534
+
535
+ instance . deleteFromQuery = instance . deleteFromQuery . where ( column , operator , value )
536
+
537
+ return instance
538
+ }
539
+
540
+ whereRef ( column : string , operator : string , value : string ) : AccessTokenModel {
541
+ this . selectFromQuery = this . selectFromQuery . whereRef ( column , operator , value )
542
+
543
+ return this
544
+ }
545
+
546
+ static whereRef ( column : string , operator : string , value : string ) : AccessTokenModel {
547
+ const instance = new AccessTokenModel ( null )
548
+
549
+ instance . selectFromQuery = instance . selectFromQuery . whereRef ( column , operator , value )
550
+
551
+ return instance
552
+ }
553
+
505
554
orWhere ( ...args : Array < [ string , string , any ] > ) : AccessTokenModel {
506
555
if ( args . length === 0 ) {
507
556
throw new HttpError ( 500 , 'At least one condition must be provided' )
@@ -558,31 +607,14 @@ export class AccessTokenModel {
558
607
return instance
559
608
}
560
609
561
- static where ( ...args : ( string | number | boolean | undefined | null ) [ ] ) : AccessTokenModel {
562
- let column : any
563
- let operator : any
564
- let value : any
565
-
566
- const instance = new AccessTokenModel ( null )
567
-
568
- if ( args . length === 2 ) {
569
- [ column , value ] = args
570
- operator = '='
571
- }
572
- else if ( args . length === 3 ) {
573
- [ column , operator , value ] = args
574
- }
575
- else {
576
- throw new HttpError ( 500 , 'Invalid number of arguments' )
577
- }
578
-
579
- instance . selectFromQuery = instance . selectFromQuery . where ( column , operator , value )
580
-
581
- instance . updateFromQuery = instance . updateFromQuery . where ( column , operator , value )
582
-
583
- instance . deleteFromQuery = instance . deleteFromQuery . where ( column , operator , value )
610
+ when (
611
+ condition : boolean ,
612
+ callback : ( query : AccessTokenModel ) => AccessTokenModel ,
613
+ ) : AccessTokenModel {
614
+ if ( condition )
615
+ callback ( this . selectFromQuery )
584
616
585
- return instance
617
+ return this
586
618
}
587
619
588
620
static when (
@@ -597,12 +629,14 @@ export class AccessTokenModel {
597
629
return instance
598
630
}
599
631
600
- when (
601
- condition : boolean ,
602
- callback : ( query : AccessTokenModel ) => AccessTokenModel ,
603
- ) : AccessTokenModel {
604
- if ( condition )
605
- callback ( this . selectFromQuery )
632
+ whereNull ( column : string ) : AccessTokenModel {
633
+ this . selectFromQuery = this . selectFromQuery . where ( ( eb : any ) =>
634
+ eb ( column , '=' , '' ) . or ( column , 'is' , null ) ,
635
+ )
636
+
637
+ this . updateFromQuery = this . updateFromQuery . where ( ( eb : any ) =>
638
+ eb ( column , '=' , '' ) . or ( column , 'is' , null ) ,
639
+ )
606
640
607
641
return this
608
642
}
@@ -621,18 +655,6 @@ export class AccessTokenModel {
621
655
return instance
622
656
}
623
657
624
- whereNull ( column : string ) : AccessTokenModel {
625
- this . selectFromQuery = this . selectFromQuery . where ( ( eb : any ) =>
626
- eb ( column , '=' , '' ) . or ( column , 'is' , null ) ,
627
- )
628
-
629
- this . updateFromQuery = this . updateFromQuery . where ( ( eb : any ) =>
630
- eb ( column , '=' , '' ) . or ( column , 'is' , null ) ,
631
- )
632
-
633
- return this
634
- }
635
-
636
658
static whereName ( value : string ) : AccessTokenModel {
637
659
const instance = new AccessTokenModel ( null )
638
660
@@ -687,6 +709,20 @@ export class AccessTokenModel {
687
709
return instance
688
710
}
689
711
712
+ whereBetween ( column : keyof AccessTokenType , range : [ any , any ] ) : AccessTokenModel {
713
+ if ( range . length !== 2 ) {
714
+ throw new Error ( 'Range must have exactly two values: [min, max]' )
715
+ }
716
+
717
+ const query = sql ` ${ sql . raw ( column as string ) } between ${ range [ 0 ] } and ${ range [ 1 ] } `
718
+
719
+ this . selectFromQuery = this . selectFromQuery . where ( query )
720
+ this . updateFromQuery = this . updateFromQuery . where ( query )
721
+ this . deleteFromQuery = this . deleteFromQuery . where ( query )
722
+
723
+ return this
724
+ }
725
+
690
726
static whereBetween ( column : keyof AccessTokenType , range : [ any , any ] ) : AccessTokenModel {
691
727
if ( range . length !== 2 ) {
692
728
throw new Error ( 'Range must have exactly two values: [min, max]' )
@@ -703,6 +739,16 @@ export class AccessTokenModel {
703
739
return instance
704
740
}
705
741
742
+ whereNotIn ( column : keyof AccessTokenType , values : any [ ] ) : AccessTokenModel {
743
+ this . selectFromQuery = this . selectFromQuery . where ( column , 'not in' , values )
744
+
745
+ this . updateFromQuery = this . updateFromQuery . where ( column , 'not in' , values )
746
+
747
+ this . deleteFromQuery = this . deleteFromQuery . where ( column , 'not in' , values )
748
+
749
+ return this
750
+ }
751
+
706
752
static whereNotIn ( column : keyof AccessTokenType , values : any [ ] ) : AccessTokenModel {
707
753
const instance = new AccessTokenModel ( null )
708
754
@@ -715,16 +761,6 @@ export class AccessTokenModel {
715
761
return instance
716
762
}
717
763
718
- whereNotIn ( column : keyof AccessTokenType , values : any [ ] ) : AccessTokenModel {
719
- this . selectFromQuery = this . selectFromQuery . where ( column , 'not in' , values )
720
-
721
- this . updateFromQuery = this . updateFromQuery . where ( column , 'not in' , values )
722
-
723
- this . deleteFromQuery = this . deleteFromQuery . where ( column , 'not in' , values )
724
-
725
- return this
726
- }
727
-
728
764
async first ( ) : Promise < AccessTokenModel | undefined > {
729
765
const model = await this . selectFromQuery . selectAll ( ) . executeTakeFirst ( )
730
766
0 commit comments