@@ -68,9 +68,10 @@ func GetFilterMethods(tables []*PostgresTable, driver string) []FilterMethod {
6868 if err != nil {
6969 return f.IsNull()
7070 }
71+ sql := fmt.Sprintf("%s.%s IN (SELECT value FROM json_each(?))", f.table, f.field)
7172 ` ,
7273 Comment : `Only include Records with a field contains in a set of values` ,
73- Sql : `.Where(fmt.Sprintf("%s.%s IN (SELECT value FROM json_each(?))", f.table, f.field) , jsonArgs)` ,
74+ Sql : `.Where(sql , jsonArgs)` ,
7475 Args : []string {"args ...T" },
7576 },
7677 SelectFilter {
@@ -80,73 +81,90 @@ func GetFilterMethods(tables []*PostgresTable, driver string) []FilterMethod {
8081 if err != nil {
8182 return f.IsNull()
8283 }
84+ sql := fmt.Sprintf("%s.%s NOT INT (SELECT value FROM json_each(?))", f.table, f.field)
8385 ` ,
8486 Comment : `Exclude Records with a field not contains in a set of values` ,
85- Sql : `.Where(fmt.Sprintf("%s.%s NOT INT (SELECT value FROM json_each(?))", f.table, f.field) , jsonArgs)` ,
87+ Sql : `.Where(sql , jsonArgs)` ,
8688 Args : []string {"args ...T" },
8789 },
8890 )
8991 } else {
9092 method .Filters = append (method .Filters ,
9193 SelectFilter {
92- Model : t ,
93- Name : "In" ,
94+ Model : t ,
95+ Name : "In" ,
96+ Pre : `sql := fmt.Sprintf("%s.%s = ANY(?)", f.table, f.field)
97+ ` ,
9498 Comment : `Only include Records with a field contains in a set of values` ,
95- Sql : `.Where(fmt.Sprintf("%s.%s = ANY(?)", f.table, f.field) , pq.Array(args))` ,
99+ Sql : `.Where(sql , pq.Array(args))` ,
96100 Args : []string {"args ...T" },
97101 },
98102 SelectFilter {
99- Model : t ,
100- Name : "NotIn" ,
103+ Model : t ,
104+ Name : "NotIn" ,
105+ Pre : `sql := fmt.Sprintf("%s.%s != ANY(?)", f.table, f.field)
106+ ` ,
101107 Comment : `Exclude Records with a field not contains in a set of values` ,
102- Sql : `.Where(fmt.Sprintf("%s.%s != ANY(?)", f.table, f.field) , pq.Array(args))` ,
108+ Sql : `.Where(sql , pq.Array(args))` ,
103109 Args : []string {"args ...T" },
104110 },
105111 )
106112 }
107113
108114 method .Filters = append (method .Filters ,
109115 SelectFilter {
110- Model : t ,
111- Name : "Equal" ,
116+ Model : t ,
117+ Name : "Equal" ,
118+ Pre : `sql := fmt.Sprintf("%s.%s = ?", f.table, f.field)
119+ ` ,
112120 Comment : `Only include Records with a field specific value` ,
113- Sql : `.Where(fmt.Sprintf("%s.%s = ?", f.table, f.field) , arg)` ,
121+ Sql : `.Where(sql , arg)` ,
114122 Args : []string {"arg T" },
115123 },
116124 SelectFilter {
117- Model : t ,
118- Name : "NotEqual" ,
125+ Model : t ,
126+ Name : "NotEqual" ,
127+ Pre : `sql := fmt.Sprintf("%s.%s != ?", f.table, f.field)
128+ ` ,
119129 Comment : `Exclude Records with a field specific value` ,
120- Sql : `.Where(fmt.Sprintf("%s.%s != ?", f.table, f.field) , arg)` ,
130+ Sql : `.Where(sql , arg)` ,
121131 Args : []string {"arg T" },
122132 },
123133
124134 SelectFilter {
125- Model : t ,
126- Name : "IsNull" ,
135+ Model : t ,
136+ Name : "IsNull" ,
137+ Pre : `sql := fmt.Sprintf("%s.%s IS NULL", f.table, f.field)
138+ ` ,
127139 Comment : `Only include Records with a field has undefined value` ,
128- Sql : `.Where(fmt.Sprintf("%s.%s IS NULL", f.table, f.field) )` ,
140+ Sql : `.Where(sql )` ,
129141 Args : []string {},
130142 },
131143 SelectFilter {
132- Model : t ,
133- Name : "IsNotNull" ,
144+ Model : t ,
145+ Name : "IsNotNull" ,
146+ Pre : `sql := fmt.Sprintf("%s.%s IS NOT NULL", f.table, f.field)
147+ ` ,
134148 Comment : `Only include Records with a field has defined values` ,
135- Sql : `.Where(fmt.Sprintf("%s.%s IS NOT NULL", f.table, f.field) )` ,
149+ Sql : `.Where(sql )` ,
136150 Args : []string {},
137151 },
138152 SelectFilter {
139- Model : t ,
140- Name : "OrderAsc" ,
153+ Model : t ,
154+ Name : "OrderAsc" ,
155+ Pre : `sql := fmt.Sprintf("%s.%s ASC", f.table, f.field)
156+ ` ,
141157 Comment : `Sort Records in ASC order` ,
142- Sql : `.OrderBy(fmt.Sprintf("%s.%s ASC", f.table, f.field) )` ,
158+ Sql : `.OrderBy(sql )` ,
143159 Args : []string {},
144160 },
145161 SelectFilter {
146- Model : t ,
147- Name : "OrderDesc" ,
162+ Model : t ,
163+ Name : "OrderDesc" ,
164+ Pre : `sql := fmt.Sprintf("%s.%s DESC", f.table, f.field)
165+ ` ,
148166 Comment : `Sort Records in DESC order` ,
149- Sql : `.OrderBy(fmt.Sprintf("%s.%s DESC", f.table, f.field) )` ,
167+ Sql : `.OrderBy(sql )` ,
150168 Args : []string {},
151169 },
152170 )
@@ -155,17 +173,21 @@ func GetFilterMethods(tables []*PostgresTable, driver string) []FilterMethod {
155173 if t == "FilterStringField" {
156174 method .Filters = append (method .Filters ,
157175 SelectFilter {
158- Model : t ,
159- Name : "Like" ,
176+ Model : t ,
177+ Name : "Like" ,
178+ Pre : `sql := fmt.Sprintf("%s.%s LIKE ?", f.table, f.field)
179+ ` ,
160180 Comment : `Only include Records with a field contains a specific value (use % as wildcard)` ,
161- Sql : `.Where(fmt.Sprintf("%s.%s LIKE ?", f.table, f.field) , arg)` ,
181+ Sql : `.Where(sql , arg)` ,
162182 Args : []string {"arg T" },
163183 },
164184 SelectFilter {
165- Model : t ,
166- Name : "NotLike" ,
185+ Model : t ,
186+ Name : "NotLike" ,
187+ Pre : `sql := fmt.Sprintf("%s.%s NOT LIKE ?", f.table, f.field)
188+ ` ,
167189 Comment : `Exclude Records with a field contains a specific value (use % as wildcard)` ,
168- Sql : `.Where(fmt.Sprintf("%s.%s NOT LIKE ?", f.table, f.field) , arg)` ,
190+ Sql : `.Where(sql , arg)` ,
169191 Args : []string {"arg T" },
170192 },
171193 )
@@ -174,38 +196,48 @@ func GetFilterMethods(tables []*PostgresTable, driver string) []FilterMethod {
174196 if t == "FilterNumericField" {
175197 method .Filters = append (method .Filters ,
176198 SelectFilter {
177- Model : t ,
178- Name : "GreaterThan" ,
199+ Model : t ,
200+ Name : "GreaterThan" ,
201+ Pre : `sql := fmt.Sprintf("%s.%s > ?", f.table, f.field)
202+ ` ,
179203 Comment : `Only include Records with a field greater than a specific value` ,
180- Sql : `.Where(fmt.Sprintf("%s.%s > ?", f.table, f.field) , arg)` ,
204+ Sql : `.Where(sql , arg)` ,
181205 Args : []string {"arg T" },
182206 },
183207 SelectFilter {
184- Model : t ,
185- Name : "GreaterThanOrEqual" ,
208+ Model : t ,
209+ Name : "GreaterThanOrEqual" ,
210+ Pre : `sql := fmt.Sprintf("%s.%s >= ?", f.table, f.field)
211+ ` ,
186212 Comment : `Only include Records with a field greater or equal than a specific value` ,
187- Sql : `.Where(fmt.Sprintf("%s.%s >= ?", f.table, f.field) , arg)` ,
213+ Sql : `.Where(sql , arg)` ,
188214 Args : []string {"arg T" },
189215 },
190216 SelectFilter {
191- Model : t ,
192- Name : "LesserThan" ,
217+ Model : t ,
218+ Name : "LesserThan" ,
219+ Pre : `sql := fmt.Sprintf("%s.%s < ?", f.table, f.field)
220+ ` ,
193221 Comment : `Only include Records with a field lesser than a specific value` ,
194- Sql : `.Where(fmt.Sprintf("%s.%s < ?", f.table, f.field) , arg)` ,
222+ Sql : `.Where(sql , arg)` ,
195223 Args : []string {"arg T" },
196224 },
197225 SelectFilter {
198- Model : t ,
199- Name : "LesserThanOrEqual" ,
226+ Model : t ,
227+ Name : "LesserThanOrEqual" ,
228+ Pre : `sql := fmt.Sprintf("%s.%s <= ?", f.table, f.field)
229+ ` ,
200230 Comment : `Only include Records with a field lesser or equal than a specific value` ,
201- Sql : `.Where(fmt.Sprintf("%s.%s <= ?", f.table, f.field) , arg)` ,
231+ Sql : `.Where(sql , arg)` ,
202232 Args : []string {"arg T" },
203233 },
204234 SelectFilter {
205- Model : t ,
206- Name : "Between" ,
235+ Model : t ,
236+ Name : "Between" ,
237+ Pre : `sql := fmt.Sprintf("%s.%s BETWEEN ? AND ?", f.table, f.field)
238+ ` ,
207239 Comment : `Only include Records with a field value in a specified range` ,
208- Sql : `.Where(fmt.Sprintf("%s.%s BETWEEN ? AND ?", f.table, f.field) , from, to)` ,
240+ Sql : `.Where(sql , from, to)` ,
209241 Args : []string {"from T" , "to T" },
210242 },
211243 )
@@ -214,10 +246,12 @@ func GetFilterMethods(tables []*PostgresTable, driver string) []FilterMethod {
214246 if t == "FilterArrayField" {
215247 method .Filters = append (method .Filters ,
216248 SelectFilter {
217- Model : t ,
218- Name : "Contains" ,
249+ Model : t ,
250+ Name : "Contains" ,
251+ Pre : `sql := fmt.Sprintf("%s.%s @> ?", f.table, f.field)
252+ ` ,
219253 Comment : `Check if a array field contains a specific value` ,
220- Sql : `.Where(fmt.Sprintf("%s.%s @> ?", f.table, f.field) , pq.Array(args))` ,
254+ Sql : `.Where(sql , pq.Array(args))` ,
221255 Args : []string {"args T" },
222256 },
223257 )
0 commit comments