tursodatabase / libsql-client-py

Python SDK for libSQL
https://libsql.org/libsql-client-py/
MIT License
44 stars 10 forks source link

DB API 2.0 #8

Closed barbieri closed 1 year ago

barbieri commented 1 year ago

This PR should wait on #7 as most of the commits will be reviewed there.

honzasp commented 1 year ago

I will have a closer look after we deal with #7 :)

barbieri commented 1 year ago

@honzasp, it's now ready to be reviewed. For the API docs, I used sphinx autodoc, so it will get the function/class docstrings.

The test suite only runs on python 3.11 since I used its code, some stuff it check is not available in older version. You can see changes to their code by downloading and diff cpython-3.11.3/Lib/test/test_sqlite3

honzasp commented 1 year ago

Do we have some performance numbers for this client with Turso?

barbieri commented 1 year ago

I didn't run any benchmarks, but I don't see why it would matter, unless you see some clear optimization to be employed. The synchronous characteristics will already add lots of latency

honzasp commented 1 year ago

I definitely see many applications where latency matters. If it turns out that code that switches from sqlite3 to Turso becomes 1000x slower, we will have hard time selling this to people :)

barbieri commented 1 year ago

I definitely see many applications where latency matters. If it turns out that code that switches from sqlite3 to Turso becomes 1000x slower, we will have hard time selling this to people :)

they exist, we can run some benchmarks, but comparing it to sqlite3 makes no sense... you'd have to use an ORM and compare the same code against mysql/postgresql... but then your have not just different transport, you have different engines.

however, as I said: what's the action on it?

Value Returning

I understand sqlite is mostly typeless, but you could easily return the sqlite3_column_type() in the columns (close by decltype) and keep each value to an encoding based strictly on that, like numbers come as string to keep precisions, strings comes as unicode and blobs are base64. Alternatively you could go with always blobs (sqlite3_column_bytes() + sqlite3_column_blob()) and let clients decode. Python, for instance, whenever you require a converter, it will always do that https://github.com/python/cpython/blob/main/Modules/_sqlite/cursor.c#L357-L374

Or you could mix both, using sqlite3_column_type() unless explicitly told by the client they want the results interpreted in another type, so you could pass a map/dict with column name (using AS "name" could help) and desired type (ie: return as blobs, as strings...) using the conversion table https://www.sqlite.org/c3ref/column_blob.html

This would save lots of bandwidth sending results and working with them.

barbieri commented 1 year ago

@honzasp squashed all the fixups, the PR is ready to be merged. Thanks for your help 🙏