3 Commits
v0.1.2 ... main

Author SHA1 Message Date
6f5748d3d3 fix 2025-08-11 23:45:36 +05:30
b25f9367ed using any for In/NotIn 2025-08-11 23:42:58 +05:30
8750f3ad95 method "In" 2025-08-11 22:37:25 +05:30
3 changed files with 23 additions and 15 deletions

28
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} 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 // EqualFold will use LOWER(column_name) = LOWER(val) for comparision
func (f Field) EqFold(val string) Conditioner { func (f Field) EqFold(val string) Conditioner {
col := f.String() col := f.String()
return &Cond{Field: "LOWER(" + col + ")", Val: val, op: " = LOWER($", action: CondActionNeedToClose, len: len(col) + 5} 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() col := f.String()
return &Cond{Field: col, Val: val, op: " != $", len: len(col) + 5} return &Cond{Field: col, Val: val, op: " != $", len: len(col) + 5}
} }
@@ -151,14 +151,22 @@ func (f Field) ILike(val string) Conditioner {
return &Cond{Field: col, Val: val, op: " ILIKE $", len: len(col) + 5} return &Cond{Field: col, Val: val, op: " ILIKE $", len: len(col) + 5}
} }
func (f Field) NotIn(val ...any) Conditioner { // In using ANY
func (f Field) In(val ...any) Conditioner {
col := f.String() col := f.String()
return &Cond{Field: col, Val: val, op: " NOT IN($", action: CondActionNeedToClose, len: len(col) + 5} return &Cond{Field: col, Val: val, op: " = ANY($", action: CondActionNeedToClose, len: len(col) + 5}
} }
// NotIn using ANY
func (f Field) NotIn(val ...any) Conditioner {
col := f.String()
return &Cond{Field: col, Val: val, op: " != ANY($", action: CondActionNeedToClose, len: len(col) + 5}
}
// NotInSubQuery using ANY
func (f Field) NotInSubQuery(qry WhereClause) Conditioner { func (f Field) NotInSubQuery(qry WhereClause) Conditioner {
col := f.String() col := f.String()
return &Cond{Field: col, Val: qry, op: " NOT IN($)", action: CondActionSubQuery} return &Cond{Field: col, Val: qry, op: " != ANY($)", action: CondActionSubQuery}
} }
// //

View File

@@ -28,7 +28,7 @@ func TestQryBuilder2(t *testing.T) {
), ),
). ).
Where( Where(
user.LastName.NEq(7), user.LastName.NotEq(7),
user.Phone.Like("%123%"), user.Phone.Like("%123%"),
user.UpdatedAt.IsNotNull(), user.UpdatedAt.IsNotNull(),
user.Email.NotInSubQuery(db.User.Select(user.ID).Where(user.ID.Eq(123))), user.Email.NotInSubQuery(db.User.Select(user.ID).Where(user.ID.Eq(123))),
@@ -104,7 +104,7 @@ func BenchmarkSelect(b *testing.B) {
), ),
). ).
Where( Where(
user.LastName.NEq(7), user.LastName.NotEq(7),
user.Phone.Like("%123%"), user.Phone.Like("%123%"),
user.Email.NotInSubQuery(db.User.Select(user.ID).Where(user.ID.Eq(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"), user.Email.Eq("aa@aa.com"),
). ).
Where( Where(
user.StatusID.NEq(1), user.StatusID.NotEq(1),
). ).
String() String()
@@ -38,7 +38,7 @@ func TestUpdateSetMap(t *testing.T) {
user.Email.Eq("aa@aa.com"), user.Email.Eq("aa@aa.com"),
). ).
Where( Where(
user.StatusID.NEq(1), user.StatusID.NotEq(1),
). ).
String() String()
@@ -59,7 +59,7 @@ func BenchmarkUpdateQuery(b *testing.B) {
user.Email.Eq("aa@aa.com"), user.Email.Eq("aa@aa.com"),
). ).
Where( Where(
user.StatusID.NEq(1), user.StatusID.NotEq(1),
). ).
String() String()
} }