diff --git a/builder/operators.go b/builder/operators.go new file mode 100644 index 00000000..b65bacea --- /dev/null +++ b/builder/operators.go @@ -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 diff --git a/builder/statement.go b/builder/statement.go new file mode 100644 index 00000000..cfcd4a0b --- /dev/null +++ b/builder/statement.go @@ -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{} +}