Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set(document_id: String, data: Dictionary) function #442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions addons/godot-firebase/firestore/firestore_collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,24 @@ func _process_request(task : FirestoreTask, document_id : String, url : String,

func get_database_url(append) -> String:
return _base_url + _extended_url.rstrip("/") + ":" + append


## @args document_id: StringName, data: Variant
## @return void
# used to SET a document, specify the document ID and new data
func set(document_id: StringName, data: Variant) -> void:
var task: FirestoreTask = FirestoreTask.new()
task.action = FirestoreTask.Task.TASK_PATCH
task.data = collection_name + "/" + document_id
var url = _get_request_url() + _separator + document_id.replace(" ", "%20")

_process_request(task, document_id, url, JSON.stringify(Utilities.dict2fields(data)))
var result = await Firebase.Firestore._handle_task_finished(task)

if result != null:
for child in get_children():
if child.doc_name == document_id:
child.replace(result, true)
break
else:
print("set_document returned null for %s %s" % [collection_name, document_id])