Skip to content

Add Binary constructor and bytes parameter serialization #816

@bgunebakan

Description

@bgunebakan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions