File tree 1 file changed +33
-4
lines changed
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:
52
52
53
53
return {'fields' : fields }
54
54
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 ):
56
83
if value == null :
57
84
return null
58
-
85
+
59
86
if value .has ("mapValue" ):
60
87
value = fields2dict (value .values ()[0 ])
61
88
elif value .has ("arrayValue" ):
62
89
value = fields2array (value .values ()[0 ])
63
90
elif value .has ("timestampValue" ):
64
91
value = Time .get_datetime_dict_from_datetime_string (value .values ()[0 ], false )
65
92
else :
66
- value = value .values ()[0 ]
67
-
93
+ var converter = FirebaseTypeConverter .new ()
94
+ value = converter .convert_value (value .keys ()[0 ], value .values ()[0 ])
95
+
68
96
return value
69
97
98
+
70
99
static func to_firebase_type (value : Variant ) -> Dictionary :
71
100
var var_type : String = ""
72
101
You can’t perform that action at this time.
0 commit comments