method "In"
This commit is contained in:
		
							
								
								
									
										19
									
								
								pgm.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								pgm.go
									
									
									
									
									
								
							@@ -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,6 +151,11 @@ 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) 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 {
 | 
					func (f Field) NotIn(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: " NOT IN($", action: CondActionNeedToClose, len: len(col) + 5}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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))),
 | 
				
			||||||
			).
 | 
								).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user