@@ -539,7 +539,7 @@ func (e avgExpr) ToSql() (sql string, args []any, err error) {
539
539
return
540
540
}
541
541
542
- // ExistsExpr helps to use EXISTS in SQL query
542
+ // existsExpr helps to use EXISTS in SQL query
543
543
type existsExpr struct {
544
544
expr Sqlizer
545
545
}
@@ -558,7 +558,7 @@ func (e existsExpr) ToSql() (sql string, args []any, err error) {
558
558
return
559
559
}
560
560
561
- // NotExistsExpr helps to use NOT EXISTS in SQL query
561
+ // notExistsExpr helps to use NOT EXISTS in SQL query
562
562
type notExistsExpr struct {
563
563
expr Sqlizer
564
564
}
@@ -577,7 +577,118 @@ func (e notExistsExpr) ToSql() (sql string, args []any, err error) {
577
577
return
578
578
}
579
579
580
- // InExpr helps to use IN in SQL query
580
+ // equalExpr helps to use = in SQL query
581
+ type equalExpr struct {
582
+ expr Sqlizer
583
+ value any
584
+ }
585
+
586
+ // Equal allows to use = in SQL query
587
+ // Ex: SelectBuilder.Where(Equal(sq.Select(...), 1))
588
+ func Equal (e Sqlizer , v any ) equalExpr {
589
+ return equalExpr {e , v }
590
+ }
591
+
592
+ func (e equalExpr ) ToSql () (sql string , args []any , err error ) {
593
+ sql , args , err = e .expr .ToSql ()
594
+ if err == nil {
595
+ sql = fmt .Sprintf ("(%s) = ?" , sql )
596
+ args = append (args , e .value )
597
+ }
598
+ return
599
+ }
600
+
601
+ // notEqualExpr helps to use <> in SQL query
602
+ type notEqualExpr equalExpr
603
+
604
+ // NotEqual allows to use <> in SQL query
605
+ // Ex: SelectBuilder.Where(NotEqual(sq.Select(...), 1))
606
+ func NotEqual (e Sqlizer , v any ) notEqualExpr {
607
+ return notEqualExpr {e , v }
608
+ }
609
+
610
+ func (e notEqualExpr ) ToSql () (sql string , args []any , err error ) {
611
+ sql , args , err = e .expr .ToSql ()
612
+ if err == nil {
613
+ sql = fmt .Sprintf ("(%s) <> ?" , sql )
614
+ args = append (args , e .value )
615
+ }
616
+ return
617
+ }
618
+
619
+ // greaterExpr helps to use > in SQL query
620
+ type greaterExpr equalExpr
621
+
622
+ // Greater allows to use > in SQL query
623
+ // Ex: SelectBuilder.Where(Greater(sq.Select(...), 1))
624
+ func Greater (e Sqlizer , v any ) greaterExpr {
625
+ return greaterExpr {e , v }
626
+ }
627
+
628
+ func (e greaterExpr ) ToSql () (sql string , args []any , err error ) {
629
+ sql , args , err = e .expr .ToSql ()
630
+ if err == nil {
631
+ sql = fmt .Sprintf ("(%s) > ?" , sql )
632
+ args = append (args , e .value )
633
+ }
634
+ return
635
+ }
636
+
637
+ // greaterOrEqualExpr helps to use >= in SQL query
638
+ type greaterOrEqualExpr equalExpr
639
+
640
+ // GreaterOrEqual allows to use >= in SQL query
641
+ // Ex: SelectBuilder.Where(GreaterOrEqual(sq.Select(...), 1))
642
+ func GreaterOrEqual (e Sqlizer , v any ) greaterOrEqualExpr {
643
+ return greaterOrEqualExpr {e , v }
644
+ }
645
+
646
+ func (e greaterOrEqualExpr ) ToSql () (sql string , args []any , err error ) {
647
+ sql , args , err = e .expr .ToSql ()
648
+ if err == nil {
649
+ sql = fmt .Sprintf ("(%s) >= ?" , sql )
650
+ args = append (args , e .value )
651
+ }
652
+ return
653
+ }
654
+
655
+ // lessExpr helps to use < in SQL query
656
+ type lessExpr equalExpr
657
+
658
+ // Less allows to use < in SQL query
659
+ // Ex: SelectBuilder.Where(Less(sq.Select(...), 1))
660
+ func Less (e Sqlizer , v any ) lessExpr {
661
+ return lessExpr {e , v }
662
+ }
663
+
664
+ func (e lessExpr ) ToSql () (sql string , args []any , err error ) {
665
+ sql , args , err = e .expr .ToSql ()
666
+ if err == nil {
667
+ sql = fmt .Sprintf ("(%s) < ?" , sql )
668
+ args = append (args , e .value )
669
+ }
670
+ return
671
+ }
672
+
673
+ // lessOrEqualExpr helps to use <= in SQL query
674
+ type lessOrEqualExpr equalExpr
675
+
676
+ // LessOrEqual allows to use <= in SQL query
677
+ // Ex: SelectBuilder.Where(LessOrEqual(sq.Select(...), 1))
678
+ func LessOrEqual (e Sqlizer , v any ) lessOrEqualExpr {
679
+ return lessOrEqualExpr {e , v }
680
+ }
681
+
682
+ func (e lessOrEqualExpr ) ToSql () (sql string , args []any , err error ) {
683
+ sql , args , err = e .expr .ToSql ()
684
+ if err == nil {
685
+ sql = fmt .Sprintf ("(%s) <= ?" , sql )
686
+ args = append (args , e .value )
687
+ }
688
+ return
689
+ }
690
+
691
+ // inExpr helps to use IN in SQL query
581
692
type inExpr struct {
582
693
column string
583
694
expr any
@@ -618,7 +729,7 @@ func (e inExpr) ToSql() (sql string, args []any, err error) {
618
729
return sql , args , err
619
730
}
620
731
621
- // NotInExpr helps to use NOT IN in SQL query
732
+ // notInExpr helps to use NOT IN in SQL query
622
733
type notInExpr inExpr
623
734
624
735
// NotIn allows to use NOT IN in SQL query
0 commit comments