Add builder
This commit is contained in:
		
							parent
							
								
									586c503a4f
								
							
						
					
					
						commit
						be7a4064ef
					
				
							
								
								
									
										60
									
								
								builder/operators.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								builder/operators.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
			
		||||
package builder
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Comparison Operators
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
// Raw raw sql
 | 
			
		||||
type Raw struct {
 | 
			
		||||
	Value string
 | 
			
		||||
	Args  []interface{} // TODO NamedArg
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Eq equal to
 | 
			
		||||
type Eq struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Neq not equal to
 | 
			
		||||
type Neq struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Gt greater than
 | 
			
		||||
type Gt struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Gte greater than or equal to
 | 
			
		||||
type Gte struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Lt less than
 | 
			
		||||
type Lt struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Lte less than or equal to
 | 
			
		||||
type Lte struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Logical Operators
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
// And TRUE if all the conditions is TRUE
 | 
			
		||||
type And []Condition
 | 
			
		||||
 | 
			
		||||
// Not TRUE if condition is false
 | 
			
		||||
type Not Condition
 | 
			
		||||
 | 
			
		||||
// Or TRUE if any of the conditions is TRUE
 | 
			
		||||
type Or []Condition
 | 
			
		||||
							
								
								
									
										59
									
								
								builder/statement.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								builder/statement.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,59 @@
 | 
			
		||||
package builder
 | 
			
		||||
 | 
			
		||||
// Column column type
 | 
			
		||||
type Column = string
 | 
			
		||||
 | 
			
		||||
// Statement GORM statement
 | 
			
		||||
type Statement struct {
 | 
			
		||||
	Dest        interface{}   // Insert, Select, Update, Delete
 | 
			
		||||
	Table       string        // Insert, Select, Update, Delete
 | 
			
		||||
	Select      []interface{} // Select
 | 
			
		||||
	Joins       []Join        // Select
 | 
			
		||||
	GroupBy     GroupBy       // Select
 | 
			
		||||
	OrderBy     OrderBy       // Select
 | 
			
		||||
	Preload     []Column      // Select
 | 
			
		||||
	Limit       Limit         // Select, Update
 | 
			
		||||
	Where       []Condition   // Select, Update, Delete
 | 
			
		||||
	Assignments []Assignment  // Insert, Update
 | 
			
		||||
	Returnnings []Column      // Insert, Update, Delete
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Condition query condition statement interface
 | 
			
		||||
type Condition interface {
 | 
			
		||||
	// ToSQL()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Join join statement
 | 
			
		||||
type Join struct {
 | 
			
		||||
	Table        string
 | 
			
		||||
	LocalField   string
 | 
			
		||||
	ForeignField string
 | 
			
		||||
	Conditions   []Condition
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GroupBy group by statement
 | 
			
		||||
type GroupBy struct {
 | 
			
		||||
	GroupByColumns []string
 | 
			
		||||
	Having         []Condition
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// OrderBy order by statement
 | 
			
		||||
type OrderBy []OrderByColumn
 | 
			
		||||
 | 
			
		||||
// OrderByColumn column used for order
 | 
			
		||||
type OrderByColumn struct {
 | 
			
		||||
	Name string
 | 
			
		||||
	Asc  bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Limit limit statement
 | 
			
		||||
type Limit struct {
 | 
			
		||||
	Limit  int
 | 
			
		||||
	Offset int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Assignment assign statement
 | 
			
		||||
type Assignment struct {
 | 
			
		||||
	Column Column
 | 
			
		||||
	Value  interface{}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user