elixir-sqlite / exqlite

An SQLite3 driver for Elixir
https://hexdocs.pm/exqlite
MIT License
217 stars 48 forks source link

Accept a list of modes to open db with nomutex option. #284

Closed ColaCheng closed 7 months ago

ColaCheng commented 7 months ago

In our use case, we only read the database and never write the data. We found this flag can open db with no mutex. It should be safe to open db as read-only and no mutex.

Ref: https://www.sqlite.org/c3ref/open.html

warmwaffles commented 7 months ago

@ColaCheng I haven't messed with readonly no mutex before. Why wouldn't this be the default for readonly?

ColaCheng commented 7 months ago

@ColaCheng I haven't messed with readonly no mutex before. Why wouldn't this be the default for readonly?

Thank you for review. I made readonly along with no mutex by default.

warmwaffles commented 7 months ago

I'll need to look at the documentation to figure out if no mutex should be the default. We are compiling sqlite with thread safety enabled, so this flag makes sense. But if we disabled thread safety on the compilation this would effectively be a no-op.

I'll accept this once I learn more

warmwaffles commented 7 months ago

@ColaCheng I think we'll need to modify mode to allow a list of modes added. After toying with this some, it's probably best to let the caller explicitly state the modes they want.

I'm thinking something like

mode: :readonly
mode: :readwrite
mode: [:readonly, :nomutex]

If the mode is just :nomutex we should raise an exception to the programmer to specify :readonly or :readwrite. Because technically, :readwrite is allowed with :nomutex although not recommended.

ColaCheng commented 7 months ago

Hi @warmwaffles, updated according to the comments. Please review it. Thanks!