From 8750f3ad95b96939575e8f9c6c1594878c060522 Mon Sep 17 00:00:00 2001 From: Ankit Patial Date: Mon, 11 Aug 2025 22:37:25 +0530 Subject: [PATCH] method "In" --- pgm.go | 19 ++++++++++++------- playground/qry_select_test.go | 4 ++-- playground/qry_update_test.go | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pgm.go b/pgm.go index b55f4ce..28508b1 100644 --- a/pgm.go +++ b/pgm.go @@ -98,19 +98,19 @@ func (f Field) IsNotNull() Conditioner { return &Cond{Field: col, op: " IS NOT NULL", len: len(col) + 12} } -// Eq is equal -func (f Field) Eq(val any) Conditioner { - col := f.String() - return &Cond{Field: col, Val: val, op: " = $", len: len(col) + 5} -} - // EqualFold will use LOWER(column_name) = LOWER(val) for comparision func (f Field) EqFold(val string) Conditioner { col := f.String() return &Cond{Field: "LOWER(" + col + ")", Val: val, op: " = LOWER($", action: CondActionNeedToClose, len: len(col) + 5} } -func (f Field) NEq(val any) Conditioner { +// Eq is equal +func (f Field) Eq(val any) Conditioner { + col := f.String() + return &Cond{Field: col, Val: val, op: " = $", len: len(col) + 5} +} + +func (f Field) NotEq(val any) Conditioner { col := f.String() return &Cond{Field: col, Val: val, op: " != $", len: len(col) + 5} } @@ -151,6 +151,11 @@ func (f Field) ILike(val string) Conditioner { return &Cond{Field: col, Val: val, op: " ILIKE $", len: len(col) + 5} } +func (f Field) In(val ...any) Conditioner { + col := f.String() + return &Cond{Field: col, Val: val, op: " IN($", action: CondActionNeedToClose, len: len(col) + 5} +} + func (f Field) NotIn(val ...any) Conditioner { col := f.String() return &Cond{Field: col, Val: val, op: " NOT IN($", action: CondActionNeedToClose, len: len(col) + 5} diff --git a/playground/qry_select_test.go b/playground/qry_select_test.go index 4843b5b..4f7cd8b 100644 --- a/playground/qry_select_test.go +++ b/playground/qry_select_test.go @@ -28,7 +28,7 @@ func TestQryBuilder2(t *testing.T) { ), ). Where( - user.LastName.NEq(7), + user.LastName.NotEq(7), user.Phone.Like("%123%"), user.UpdatedAt.IsNotNull(), user.Email.NotInSubQuery(db.User.Select(user.ID).Where(user.ID.Eq(123))), @@ -104,7 +104,7 @@ func BenchmarkSelect(b *testing.B) { ), ). Where( - user.LastName.NEq(7), + user.LastName.NotEq(7), user.Phone.Like("%123%"), user.Email.NotInSubQuery(db.User.Select(user.ID).Where(user.ID.Eq(123))), ). diff --git a/playground/qry_update_test.go b/playground/qry_update_test.go index addf9c9..63cf2c6 100644 --- a/playground/qry_update_test.go +++ b/playground/qry_update_test.go @@ -17,7 +17,7 @@ func TestUpdateQuery(t *testing.T) { user.Email.Eq("aa@aa.com"), ). Where( - user.StatusID.NEq(1), + user.StatusID.NotEq(1), ). String() @@ -38,7 +38,7 @@ func TestUpdateSetMap(t *testing.T) { user.Email.Eq("aa@aa.com"), ). Where( - user.StatusID.NEq(1), + user.StatusID.NotEq(1), ). String() @@ -59,7 +59,7 @@ func BenchmarkUpdateQuery(b *testing.B) { user.Email.Eq("aa@aa.com"), ). Where( - user.StatusID.NEq(1), + user.StatusID.NotEq(1), ). String() }