Managing several databases via a single repo?
Opened this issue ยท 9 comments
๐@ConnorRigby
Firstly, thank you for taking care of this project!
Secondly, I have a question ... I'm playing around with a riak core + sqlite(s) setup, and thought it would be nice to have a "pool" of sqlites on each node to allow for at least some concurrency. So is it possible to have multiple databases open for a single repo? If not, should I start a repo for each opened database? Or maybe I should just use sqlitex directly?
Can you give an example of a problem you are trying to solve?
For what it is worth this adapter uses pool boy which by default starts a pool of 10 processes that handle incoming calls. The Sqlite website/docs has a pretty opinionated page on concurrent programming and how they don't really think it's a great idea for Sqlite. Basically you can have many different connections open to Sqlite reading data no problem, but there can only ever be exactly one write at a time.
but there can only ever be exactly one write at a time.
That's what I want to avoid by having multiple databases (files) open.
Can you give an example of a problem you are trying to solve?
Say, I'm building a chatbot for learning foreign words. Each user of this chat bot would get a separate sqlite database where their (learned) words would be stored. Like /var/chatbot/user1.sqlite3, /var/chatbot/user123.sqlite3, etc. But I'd still want to manage those databases from a single Repo module, maybe by just using a prefix to identify the database.
So the same file open multiple times, or the same Repo opening many replicas of the same data?
Neither, I guess. The repo would open multiple separate databases. All they would have in common would be their schemas.
I want something similar to http://www.actordb.com/, but much simpler and without raft.
I'll try using separate repos (for each user's database) under a dynamic supervisor for now.
I'll try using separate repos (for each user's database) under a dynamic supervisor for now.
Ok, it wasn't as easy as I'd imagined since ecto repo seems to be somewhat of a "singleton" in version 2. So I had to use ecto v3-dev.
https://github.com/servers-and-stuff/dynamic_repo_sqlite
Migrations don't work yet, though.
I have a similar need. Looks like once ecto_sqlite2 supports ecto 3, this should become easy to do.