piccolo-orm / piccolo

A fast, user friendly ORM and query builder which supports asyncio.
https://piccolo-orm.com/
MIT License
1.45k stars 91 forks source link

Support arrays of timestamp / timestamptz / date / time in SQLite #1003

Closed dantownsend closed 5 months ago

dantownsend commented 5 months ago

We don't currently support things like this in SQLite:

class MyTable(Table):
    times = Array(Time())

SQLite doesn't have native support for array columns. The way we support it in Piccolo is by serialising the array into a string before storing it in the database, and deserialising it again when querying the row.

We use JSON to do the serialisation / deserialisation, which doesn't support datetime / date / time out of the box.

To support this, we'll need to create new row types for SQLite - like ARRAY_TIME / ARRAY_TIMESTAMP etc. When we read data from a row with this column type, we know we need to deserialise the values back into a list of Python objects.

One of the reasons we need this functionality is because we're doing a lot of improvements to arrays in Piccolo Admin, and we often test on SQLite.