PEP 249 (DB-API 2.0) specifies that drivers should provide a Binary(string) type constructor for working with binary data. crate-python currently omits it, and passing raw bytes as a SQL parameter raises TypeError from orjson because json_encoder() has no handler for bytes.
Current behaviour
Create a table with binary columns:
CREATE TABLE t_binary (flags BIT(8))
conn = crate.client.connect("localhost:4200")
cur = conn.cursor()
cur.execute("INSERT INTO t_binary (data) VALUES (?)", (b"\x00\xff",))
# TypeError: Type is not JSON serializable: bytes
Root cause
json_encoder() in src/crate/client/http.py covers Decimal, datetime, date, and time, but not bytes. There is also no Binary symbol exported from the module.
Notes
PEP 249 (DB-API 2.0) specifies that drivers should provide a
Binary(string)type constructor for working with binary data.crate-pythoncurrently omits it, and passing rawbytesas a SQL parameter raisesTypeErrorfromorjsonbecausejson_encoder()has no handler forbytes.Current behaviour
Create a table with binary columns:
CREATE TABLE t_binary (flags BIT(8))Root cause
json_encoder()insrc/crate/client/http.pycoversDecimal,datetime,date, andtime, but notbytes. There is also noBinarysymbol exported from the module.Notes