MCPcopy Create free account
hub / github.com/piccolo-orm/piccolo / convert_array_in

Function convert_array_in

piccolo/engine/sqlite.py:94–123  ·  view source on GitHub ↗

Converts a list value into a string (it handles nested lists, and type like dateime/ time / date which aren't usually JSON serialisable.).

(value: list)

Source from the content-addressed store, hash-verified

92
93
94def convert_array_in(value: list) -> str:
95 """
96 Converts a list value into a string (it handles nested lists, and type like
97 dateime/ time / date which aren't usually JSON serialisable.).
98
99 """
100
101 def serialise(data: list):
102 output = []
103
104 for item in data:
105 if isinstance(item, list):
106 output.append(serialise(item))
107 elif isinstance(
108 item,
109 (datetime.datetime, datetime.time, datetime.date, Decimal),
110 ):
111 if adapter := ADAPTERS.get(type(item)):
112 output.append(adapter(item))
113 else:
114 raise ValueError("The adapter wasn't found.")
115 elif item is None or isinstance(item, (str, int, float, list)):
116 # We can safely JSON serialise these.
117 output.append(item)
118 else:
119 raise ValueError("We can't currently serialise this value.")
120
121 return output
122
123 return dump_json(serialise(value))
124
125
126###############################################################################

Callers

nothing calls this directly

Calls 2

dump_jsonFunction · 0.90
serialiseFunction · 0.85

Tested by

no test coverage detected