crystal-lang / crystal-sqlite3

SQLite3 bindings for Crystal
MIT License
139 stars 30 forks source link

Support for PRAGMAs via query params? #84

Closed luislavena closed 1 year ago

luislavena commented 1 year ago

Hello folks,

Been using crystal-sqlite3 a lot recently and found a bit cumbersome to use DB#setup_connection on every codebase. Things outside of DB pool size or retry timeout cannot be controlled or passed to the lower level driver.

When looked at crystal-sqlite3 source noticed a TODO for enabling URI support for additional options:

https://github.com/crystal-lang/crystal-sqlite3/blob/master/src/sqlite3/connection.cr#L5-L6

But the recognized query parameters provided by that are quite limited.

Comparing this with other implementations of sqlite3 in other languages like Go (example mattn/go-sqlite3), saw out-of-the-box support for foreign keys, timeout and journal mode (see feature list).

Made an attempt to explore adding this, but encountered that couldn't use #exec directly from within the connection initialize, as this is being instantiated by the Pool and exec tries to access the pool to pick a connection from it, and then 💣

Saw comments in #48 about considering broader support for things like this.

The SQLite3 example of setting PRAGMAs is one, but other examples like TLS support for MySQL comes to my mind. Perhaps something for this could be added to the abstraction that allows doing these adjustments on a per-driver basis?

(perhaps should be posting this on crystal-db instead, but better ask somewhere).

Thank you in advance for your responses! 😊

❤️ ❤️ ❤️