Skip to content

Commit ffad3d3

Browse files
authored
Merge pull request #31 from fenix-hub/dev
Update v3.0.2
2 parents f06f699 + ee91b38 commit ffad3d3

File tree

8 files changed

+92
-45
lines changed

8 files changed

+92
-45
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Project specific files
2+
.env
3+
export/
4+
scn/
5+
project.godot
6+
icon.png
7+
*.import
8+
9+
# Godot-specific ignores
10+
.import/
11+
export.cfg
12+
export_presets.cfg
13+
default_env.tres
14+
15+
# Imported translations (automatically generated from CSV files)
16+
*.translation
17+
18+
# Mono-specific ignores
19+
.mono/
20+
data_*/

addons/supabase/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[supabase/config]
2+
3+
supabaseUrl=""
4+
supabaseKey=""

addons/supabase/Database/database_error.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ var code : String = "empty"
66
#var id : int = -1
77
var message : String = "empty"
88
var hint : String = "empty"
9-
var details : String = "empty"
9+
var details
1010

1111
func _init(dictionary : Dictionary = {}) -> void:
1212
_error = dictionary
1313
if not _error.empty():
1414
code = _error.code if _error.has("code") else "empty"
1515
message = _error.message
1616
hint = _error.hint if _error.has("hint") and _error.hint != null else "empty"
17-
details = _error.details if _error.has("details") and _error.details != null else "empty"
17+
details = _error.get("details", "")
1818
### always different behavior ???
1919

2020
func _to_string():

addons/supabase/Database/query.gd

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ var query_struct : Dictionary = {
55
table = "",
66
select = PoolStringArray([]),
77
order = PoolStringArray([]),
8+
Or = PoolStringArray([]),
89
eq = PoolStringArray([]),
910
neq = PoolStringArray([]),
1011
like = PoolStringArray([]),
1112
ilike = PoolStringArray([]),
12-
IS = PoolStringArray([]),
13+
Is = PoolStringArray([]),
1314
in = PoolStringArray([]),
1415
fts = PoolStringArray([]),
1516
plfts = PoolStringArray([]),
@@ -56,7 +57,8 @@ enum Filters {
5657
FTS,
5758
PLFTS,
5859
PHFLTS,
59-
WFTS
60+
WFTS,
61+
OR
6062
}
6163

6264
func _init(_raw_query : String = "", _raw_type : int = -1, _raw_header : PoolStringArray = [], _raw_body : String = ""):
@@ -72,14 +74,17 @@ func build_query() -> String:
7274
if raw_query == "" and query == raw_query:
7375
for key in query_struct:
7476
if query_struct[key].empty(): continue
77+
if query.length() > 0 : if not query[query.length()-1] in ["/","?"]: query+="&"
7578
match key:
7679
"table":
7780
query += query_struct[key]
7881
"select", "order":
7982
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":
8285
query += PoolStringArray(query_struct[key]).join("&")
86+
"Or":
87+
query += "or=(%s)"%[query_struct[key].join(",")]
8388
return query
8489

8590

@@ -90,7 +95,7 @@ func from(table_name : String) -> SupabaseQuery:
9095
# Insert new Row
9196
func insert(fields : Array, upsert : bool = false) -> SupabaseQuery:
9297
request = REQUESTS.INSERT
93-
body = JSON.print(fields)
98+
body = to_json(fields)
9499
if upsert : header += PoolStringArray(["Prefer: resolution=merge-duplicates"])
95100
return self
96101

@@ -103,7 +108,7 @@ func select(columns : PoolStringArray = PoolStringArray(["*"])) -> SupabaseQuery
103108
# Update Rows
104109
func update(fields : Dictionary) -> SupabaseQuery:
105110
request = REQUESTS.UPDATE
106-
body = JSON.print(fields)
111+
body = to_json(fields)
107112
return self
108113

109114
# Delete Rows
@@ -132,30 +137,43 @@ func order(column : String, direction : int = Directions.Ascending, nullsorder :
132137
## [FILTERS] --------------------------------------------------------------------
133138

134139
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:
135159
var filter_str : String
136160
match filter:
137161
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"
139166
Filters.GREATER_THAN: filter_str = "gt"
140-
Filters.LESS_THAN: filter_str = "lt"
141167
Filters.GREATER_THAN_OR_EQUAL: filter_str = "gte"
142-
Filters.LESS_THAN_OR_EQUAL: filter_str = "lte"
143168
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"
148173
Filters.PLFTS: filter_str = "plfts"
149174
Filters.PHFTS: filter_str = "phfts"
150175
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
159177

160178
# Finds all rows whose value on the stated columns match the specified values.
161179
func match(query_dict : Dictionary) -> SupabaseQuery:
@@ -195,7 +213,7 @@ func lte(column : String, value : String) -> SupabaseQuery:
195213

196214
# Finds all rows whose value in the stated column matches the supplied pattern (case sensitive).
197215
func like(column : String, value : String) -> SupabaseQuery:
198-
filter(column, Filters.LIKE, value)
216+
filter(column, Filters.LIKE, "*%s*"%value)
199217
return self
200218

201219
# 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:
204222
return self
205223

206224
# 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})
209227
return self
210228

211229
# Finds all rows whose value on the stated column is found on the specified values.
212230
func In(column : String, array : PoolStringArray) -> SupabaseQuery:
213231
filter(column, Filters.IN, "("+array.join(",")+")")
214232
return self
215233

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})
218236
return self
219237

220238
# Text Search

addons/supabase/Realtime/realtime_client.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,22 @@ func _on_data() -> void:
109109
PhxEvents.REPLY:
110110
if _check_response(data) == 0:
111111
pass
112-
# print("Received reply = "+to_json(data))
112+
print_debug("Received reply = "+to_json(data))
113113
PhxEvents.JOIN:
114114
if _check_response(data) == 0:
115115
pass
116-
# print("Joined topic '%s'" % data.topic)
116+
print_debug("Joined topic '%s'" % data.topic)
117117
PhxEvents.LEAVE:
118118
if _check_response(data) == 0:
119119
pass
120-
# print("Left topic '%s'" % data.topic)
120+
print_debug("Left topic '%s'" % data.topic)
121121
PhxEvents.CLOSE:
122122
pass
123-
# print("Channel closed.")
123+
print_debug("Channel closed.")
124124
PhxEvents.ERROR:
125125
emit_signal("error", data.payload)
126126
SupabaseEvents.DELETE, SupabaseEvents.INSERT, SupabaseEvents.UPDATE:
127-
# print("Received %s event..." % data.event)
127+
print_debug("Received %s event..." % data.event)
128128
var channel : RealtimeChannel = get_channel(data.topic)
129129
if channel != null:
130130
channel._publish(data)

addons/supabase/Storage/storage_bucket.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,18 @@ func upload(object : String, file_path : String, upsert : bool = false) -> Stora
9292
var file : File = File.new()
9393
var error : int = file.open(file_path, File.READ)
9494
if error != OK:
95+
printerr("could not open %s "%file_path)
9596
task.complete({})
9697
return task
9798
var header : PoolStringArray = [_header[0] % MIME_TYPES.get(file_path.get_extension(), "application/octet-stream")]
9899
header.append("Content-Length: %s" % file.get_len())
100+
header.append("x-upsert: %s" % upsert)
99101
task.connect("completed", self, "_on_task_completed")
100102
task._setup(
101103
task.METHODS.UPLOAD_OBJECT,
102104
endpoint,
103105
header + _bearer,
104-
to_json({upsert = upsert}),
106+
"",
105107
file.get_buffer(file.get_len())
106108
)
107109
_current_task = task

addons/supabase/Supabase/supabase.gd

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extends Node
22

3-
const ENVIRONMENT_VARIABLES : String = "supabase/config/"
3+
const ENVIRONMENT_VARIABLES : String = "supabase/config"
44

55
var auth : SupabaseAuth
66
var database : SupabaseDatabase
@@ -24,16 +24,19 @@ func _ready() -> void:
2424
# Load all config settings from ProjectSettings
2525
func load_config() -> void:
2626
if config.supabaseKey != "" and config.supabaseUrl != "":
27-
return
28-
for key in config.keys():
29-
if ProjectSettings.has_setting(ENVIRONMENT_VARIABLES+key):
30-
var value : String = ProjectSettings.get_setting(ENVIRONMENT_VARIABLES+key)
31-
if value == "":
32-
printerr("%s has not a valid value." % key)
33-
else:
34-
config[key] = value
27+
pass
28+
else:
29+
var env = ConfigFile.new()
30+
var err = env.load("res://addons/supabase/.env")
31+
if err == OK:
32+
for key in config.keys():
33+
var value : String = env.get_value(ENVIRONMENT_VARIABLES, key, "")
34+
if value == "":
35+
printerr("%s has not a valid value." % key)
36+
else:
37+
config[key] = value
3538
else:
36-
printerr("%s key is not defined." % key)
39+
printerr("Unable to read .env file at path 'res://.env'")
3740
header.append("apikey: %s"%[config.supabaseKey])
3841

3942
func load_nodes() -> void:

addons/supabase/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="Supabase"
44
description="A lightweight addon which integrates Supabase APIs for Godot Engine out of the box."
55
author="Nicolò (fenix-hub) Santilio"
6-
version="1.3"
6+
version="3.0.2"
77
script="plugin.gd"

0 commit comments

Comments
 (0)