@@ -5,11 +5,12 @@ var query_struct : Dictionary = {
5
5
table = "" ,
6
6
select = PoolStringArray ([]),
7
7
order = PoolStringArray ([]),
8
+ Or = PoolStringArray ([]),
8
9
eq = PoolStringArray ([]),
9
10
neq = PoolStringArray ([]),
10
11
like = PoolStringArray ([]),
11
12
ilike = PoolStringArray ([]),
12
- IS = PoolStringArray ([]),
13
+ Is = PoolStringArray ([]),
13
14
in = PoolStringArray ([]),
14
15
fts = PoolStringArray ([]),
15
16
plfts = PoolStringArray ([]),
@@ -56,7 +57,8 @@ enum Filters {
56
57
FTS ,
57
58
PLFTS ,
58
59
PHFLTS ,
59
- WFTS
60
+ WFTS ,
61
+ OR
60
62
}
61
63
62
64
func _init (_raw_query : String = "" , _raw_type : int = - 1 , _raw_header : PoolStringArray = [], _raw_body : String = "" ):
@@ -72,14 +74,17 @@ func build_query() -> String:
72
74
if raw_query == "" and query == raw_query :
73
75
for key in query_struct :
74
76
if query_struct [key ].empty (): continue
77
+ if query .length () > 0 : if not query [query .length ()- 1 ] in ["/" ,"?" ]: query += "&"
75
78
match key :
76
79
"table" :
77
80
query += query_struct [key ]
78
81
"select" , "order" :
79
82
if query_struct [key ].empty (): continue
80
- query += (key + "=" + PoolStringArray (query_struct [key ]).join ("," )+ "&" )
81
- "eq" , "neq" , "lt" , "gt" , "lte" , "gte" , "like" , "ilike" , "IS " , "in" , "fts" , "plfts" , "phfts" , "wfts" :
83
+ query += (key + "=" + PoolStringArray (query_struct [key ]).join ("," ))
84
+ "eq" , "neq" , "lt" , "gt" , "lte" , "gte" , "like" , "ilike" , "Is " , "in" , "fts" , "plfts" , "phfts" , "wfts" :
82
85
query += PoolStringArray (query_struct [key ]).join ("&" )
86
+ "Or" :
87
+ query += "or=(%s )" % [query_struct [key ].join ("," )]
83
88
return query
84
89
85
90
@@ -90,7 +95,7 @@ func from(table_name : String) -> SupabaseQuery:
90
95
# Insert new Row
91
96
func insert (fields : Array , upsert : bool = false ) -> SupabaseQuery :
92
97
request = REQUESTS .INSERT
93
- body = JSON . print (fields )
98
+ body = to_json (fields )
94
99
if upsert : header += PoolStringArray (["Prefer: resolution=merge-duplicates" ])
95
100
return self
96
101
@@ -103,7 +108,7 @@ func select(columns : PoolStringArray = PoolStringArray(["*"])) -> SupabaseQuery
103
108
# Update Rows
104
109
func update (fields : Dictionary ) -> SupabaseQuery :
105
110
request = REQUESTS .UPDATE
106
- body = JSON . print (fields )
111
+ body = to_json (fields )
107
112
return self
108
113
109
114
# Delete Rows
@@ -132,30 +137,43 @@ func order(column : String, direction : int = Directions.Ascending, nullsorder :
132
137
## [FILTERS] --------------------------------------------------------------------
133
138
134
139
func filter (column : String , filter : int , value : String , _props : Dictionary = {}) -> SupabaseQuery :
140
+ var filter_str : String = match_filter (filter )
141
+ var array : PoolStringArray = query_struct [filter_str ] as PoolStringArray
142
+ var struct_filter : String = filter_str
143
+ if _props .has ("config" ):
144
+ struct_filter += "({config} )" .format (_props )
145
+ if _props .has ("negate" ):
146
+ struct_filter = ("not." + struct_filter ) if _props .get ("negate" ) else struct_filter
147
+ # Apply custom logic or continue with default logic
148
+ match filter_str :
149
+ "Or" :
150
+ if _props .has ("queries" ):
151
+ for query in _props .get ("queries" ):
152
+ array .append (query .build_query ().replace ("=" ,"." ) if (not query is String ) else query )
153
+ _ :
154
+ array .append ("%s =%s .%s " % [column , struct_filter .to_lower (), value ])
155
+ query_struct [filter_str ] = array
156
+ return self
157
+
158
+ func match_filter (filter : int ) -> String :
135
159
var filter_str : String
136
160
match filter :
137
161
Filters .EQUAL : filter_str = "eq"
138
- Filters .NOT_EQUAL : filter_str = "neq"
162
+ Filters .FTS : filter_str = "fts"
163
+ Filters .ILIKE : filter_str = "ilike"
164
+ Filters .IN : filter_str = "in"
165
+ Filters .IS : filter_str = "Is"
139
166
Filters .GREATER_THAN : filter_str = "gt"
140
- Filters .LESS_THAN : filter_str = "lt"
141
167
Filters .GREATER_THAN_OR_EQUAL : filter_str = "gte"
142
- Filters .LESS_THAN_OR_EQUAL : filter_str = "lte"
143
168
Filters .LIKE : filter_str = "like"
144
- Filters .ILIKE : filter_str = "ilike "
145
- Filters .IS : filter_str = "is "
146
- Filters .IN : filter_str = "in "
147
- Filters .FTS : filter_str = "fts "
169
+ Filters .LESS_THAN : filter_str = "lt "
170
+ Filters .LESS_THAN_OR_EQUAL : filter_str = "lte "
171
+ Filters .NOT_EQUAL : filter_str = "neq "
172
+ Filters .OR : filter_str = "Or "
148
173
Filters .PLFTS : filter_str = "plfts"
149
174
Filters .PHFTS : filter_str = "phfts"
150
175
Filters .WFTS : filter_str = "wfts"
151
- var array : PoolStringArray = query_struct [filter_str ] as PoolStringArray
152
- var struct_filter : String = filter_str
153
- if _props .has ("config" ):
154
- struct_filter += "({config} )" .format (_props )
155
- array .append ("%s =%s .%s " % [column , struct_filter , value ])
156
- query_struct [filter_str ] = array
157
- return self
158
-
176
+ return filter_str
159
177
160
178
# Finds all rows whose value on the stated columns match the specified values.
161
179
func match (query_dict : Dictionary ) -> SupabaseQuery :
@@ -195,7 +213,7 @@ func lte(column : String, value : String) -> SupabaseQuery:
195
213
196
214
# Finds all rows whose value in the stated column matches the supplied pattern (case sensitive).
197
215
func like (column : String , value : String ) -> SupabaseQuery :
198
- filter (column , Filters .LIKE , value )
216
+ filter (column , Filters .LIKE , "* %s *" % value )
199
217
return self
200
218
201
219
# Finds all rows whose value in the stated column matches the supplied pattern (case insensitive).
@@ -204,17 +222,17 @@ func ilike(column : String, value : String) -> SupabaseQuery:
204
222
return self
205
223
206
224
# A check for exact equality (null, true, false), finds all rows whose value on the stated column exactly match the specified value.
207
- func Is (column : String , value ) -> SupabaseQuery :
208
- filter (column , Filters .IS , str (value ))
225
+ func Is (column : String , value , negate : bool = false ) -> SupabaseQuery :
226
+ filter (column , Filters .IS , str (value ), { negate = negate } )
209
227
return self
210
228
211
229
# Finds all rows whose value on the stated column is found on the specified values.
212
230
func In (column : String , array : PoolStringArray ) -> SupabaseQuery :
213
231
filter (column , Filters .IN , "(" + array .join ("," )+ ")" )
214
232
return self
215
233
216
- func Or (column : String , value : String ) -> SupabaseQuery :
217
- filter (column , Filters .OR , value )
234
+ func Or (queries : Array ) -> SupabaseQuery :
235
+ filter ("" , Filters .OR , "" , { queries = queries } )
218
236
return self
219
237
220
238
# Text Search
0 commit comments