Skip to content

Allow more array types for SQLite #941

@dantownsend

Description

@dantownsend

The way we store arrays in SQLite is by converting the values to JSON strings, and then storing them in a text field.

We have this function which converts list values into JSON:

def convert_array_in(value: list):
"""
Converts a list value into a string.
"""
if value and type(value[0]) not in [str, int, float, list]:
raise ValueError("Can only serialise str, int, float, and list.")
return dump_json(value)

We validate the types here to make sure we can serialise it.

The list of types is fairly limited - it excludes Decimal, date, and datetime, because Python's json.dumps is pretty restrictive. We might be able to extend json.dumps to handle these additional types.

Note - if orjson is installed, this is less of a problem, as it serialises far more types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions