42
42
43
43
44
44
def convert_change_data (columns , records , options = {}):
45
- result = {}
46
45
skip_types = options .get ("skip_types" ) if options .get (
47
46
"skip_types" ) == "undefined" else []
48
- for key in records .keys ():
49
- result [key ] = convert_column (key , columns , records , skip_types )
50
- return result
47
+ return {
48
+ key : convert_column (key , columns , records , skip_types )
49
+ for key in records .keys ()
50
+ }
51
51
52
52
53
53
def convert_column (column_name , columns , records , skip_types ):
@@ -60,11 +60,11 @@ def convert_column(column_name, columns, records, skip_types):
60
60
61
61
def convert_cell (_type : str , string_value : str ):
62
62
try :
63
- if string_value == None :
63
+ if string_value is None :
64
64
return None
65
65
# If data type is an array
66
66
if _type [0 ] == "_" :
67
- array_value = _type [1 , len (_type )]
67
+ array_value = _type [1 : len (_type )]
68
68
return to_array (string_value , array_value )
69
69
# If it's not null then we need to convert it to the correct type
70
70
if _type == abstime :
@@ -87,9 +87,9 @@ def convert_cell(_type: str, string_value: str):
87
87
elif _type == int4range :
88
88
return to_int_range (string_value )
89
89
elif _type == int8 :
90
- return to_int_range (string_value )
91
- elif _type == int8range :
92
90
return to_int (string_value )
91
+ elif _type == int8range :
92
+ return to_int_range (string_value )
93
93
elif _type == _json :
94
94
return to_json (string_value )
95
95
elif _type == jsonb :
@@ -111,11 +111,9 @@ def convert_cell(_type: str, string_value: str):
111
111
string_value
112
112
) # Format to be consistent with PostgREST
113
113
elif _type == timestamptz :
114
- # To allow users to cast it based on Timezone
115
- return noop (string_value )
114
+ return parse (string_value )
116
115
elif _type == timetz :
117
- # To allow users to cast it based on Timezone
118
- return noop (string_value )
116
+ return parse (string_value )
119
117
elif _type == tsrange :
120
118
return to_date_range (string_value )
121
119
elif _type == tstzrange :
@@ -187,8 +185,7 @@ def to_array(string_value: str, type: str):
187
185
# if string is empty (meaning the array was empty), an empty array will be immediately returned
188
186
string_array = string_enriched .split (
189
187
"," ) if len (string_enriched ) > 0 else []
190
- array = list (map (lambda string : convert_cell (type , string ), string_array ))
191
- return array
188
+ return list (map (lambda string : convert_cell (type , string ), string_array ))
192
189
193
190
194
191
"""
0 commit comments