Closed fenix-hub closed 3 years ago
@fenix-hub looks like you accidentally committed project.godot
changes in this PR. Might want to rotate those keys.
@timjrobinson Thank you for noticing, I'll delete them even though it is not much of a problem for Firebase keys to be exposed.
This PR will integrate automatic parsing/marshalling of
FirestoreDocument
s inFirestoreCollection
functions.FirestoreCollection
management functions such asadd(document_name, document)
andupdate(document_name, document)
it was necessary to create aFirestoreDocument
and call a parsing functiondict2fields(dictionary)
in order to parse a GDscriptDictionary
to a formatted body accepted by Firestore API (which is in the form of{fields: { var_type: {name:value} }}
). In the same way, Firebase return bodies needed to be formatted to a Dictionary in order to make them more readable and usable in gdscript using the functionfields2dict(document.fields)
.{fields: {string: {"user":"user_name"}}}
|{"user":"user_name"}
This PR will apply the following changes:
dict2fields()
andfields2dict()
are nowstatic
functions, so if you want to call them, there's no need to create an empty FirestoreDocument anymore. Instead, they can be called like so:FirestoreDocument.dict2fields(dictionary)
dict2fields
will be automatically called insideadd()
andupdate()
functions on FirestoreCollection objects. This way, to create or update a new document you will just need to pass aDictionary
like so:a_collection.add("", {"a_field":"a_value"})
fields2dict
will be automatically called upon receiving a FirestoreDocument from FirestoreCollection signals, and this value will be saved inside aFirestoreDocument
doc_fields
parameter. So, when receiving a document from a signal (for instance - calling theget(document_id)
function on a FirestoreCollection), a dictionary of its fields will be put insidefirestore_document.doc_fields
as a Dictionary.print(document)
on a FirestoreDocument will print an auto-formatted document, like this: