File tree Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -52,21 +52,50 @@ static func dict2fields(dict : Dictionary) -> Dictionary:
5252
5353 return {'fields' : fields }
5454
55- static func from_firebase_type (value : Variant ) -> Variant :
55+
56+ class FirebaseTypeConverter extends RefCounted :
57+ var converters = {
58+ "nullValue" : _to_null ,
59+ "booleanValue" : _to_bool ,
60+ "integerValue" : _to_int ,
61+ "doubleValue" : _to_float
62+ }
63+
64+ func convert_value (type , value ):
65+ if converters .has (type ):
66+ return converters [type ].call (value )
67+
68+ return value
69+
70+ func _to_null (value ):
71+ return null
72+
73+ func _to_bool (value ):
74+ return bool (value )
75+
76+ func _to_int (value ):
77+ return int (value )
78+
79+ func _to_float (value ):
80+ return float (value )
81+
82+ static func from_firebase_type (value ):
5683 if value == null :
5784 return null
58-
85+
5986 if value .has ("mapValue" ):
6087 value = fields2dict (value .values ()[0 ])
6188 elif value .has ("arrayValue" ):
6289 value = fields2array (value .values ()[0 ])
6390 elif value .has ("timestampValue" ):
6491 value = Time .get_datetime_dict_from_datetime_string (value .values ()[0 ], false )
6592 else :
66- value = value .values ()[0 ]
67-
93+ var converter = FirebaseTypeConverter .new ()
94+ value = converter .convert_value (value .keys ()[0 ], value .values ()[0 ])
95+
6896 return value
6997
98+
7099static func to_firebase_type (value : Variant ) -> Dictionary :
71100 var var_type : String = ""
72101
You can’t perform that action at this time.
0 commit comments