Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
b25f9367ed | |||
8750f3ad95 |
28
pgm.go
28
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,14 +151,22 @@ func (f Field) ILike(val string) Conditioner {
|
||||
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()
|
||||
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 {
|
||||
col := f.String()
|
||||
return &Cond{Field: col, Val: qry, op: " NOT IN($)", action: CondActionSubQuery}
|
||||
return &Cond{Field: col, Val: qry, op: " != ANY($)", action: CondActionSubQuery}
|
||||
}
|
||||
|
||||
//
|
||||
|
@@ -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))),
|
||||
).
|
||||
|
@@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user