method "In"

This commit is contained in:
2025-08-11 22:37:25 +05:30
parent ad1faf2056
commit 8750f3ad95
3 changed files with 17 additions and 12 deletions

19
pgm.go
View File

@@ -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}

View File

@@ -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))),
).

View File

@@ -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()
}