Skip to content

Add Binary constructor and bytes parameter serialization #816

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions