Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request]: Allow multiple connections and restrict threads to 1 per connection #202

Closed
ospfranco opened this issue Dec 13, 2024 · 0 comments · Fixed by #204
Closed

[Request]: Allow multiple connections and restrict threads to 1 per connection #202

ospfranco opened this issue Dec 13, 2024 · 0 comments · Fixed by #204
Assignees
Labels
enhancement New feature or request

Comments

@ospfranco
Copy link
Contributor

ospfranco commented Dec 13, 2024

What do you need?

Currently there are some limitations with the architecture of op-sqlite:

  • All connections are kept alive in a single map. This limits the amount of connections one can keep alive to one per db "name". This was a simplistic design based on the limitations of the old bridge.
  • There is a shared thread pool without any concurrency guarantees. This works well to offload work of the main thread and not block the UI, but as people start doing more and more tasks in parallel the risk of race conditions increases. This is clear with some issues like: Gotcha with async prepared statement execution #199. There is a way to prevent race conditions via db.transaction but this means ALL operations (including reads) need to use a transaction, which is not practical, also, hard to communicate as people don't read the docs in detail.

The plan here is to re-work the architecture of the library. To limit a thread per connection and to move the database object to a HostObject. Then the connection no longer needs to be manually managed on the C++ side of things and can just be returned to JS to be managed by the JS engine. This will not only allow to have multiple connections but also solve threading issues as then sqlite can handle the thread calls on its own by managing the connections.

One can then create a single "write" connection, do all the operations in there without fear of overwrites and multiple read connections, which sqlite guaranteeing the order of operations.

@ospfranco ospfranco added the enhancement New feature or request label Dec 13, 2024
@ospfranco ospfranco self-assigned this Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant