-
Notifications
You must be signed in to change notification settings - Fork 67
Open
Description
In #1089 we now have a way to specify different Read and Write databases. One case I wasn't able to figure out a good solution for is when you might need to override this value on the fly for specific edge cases.
Imagine something along these lines:
# temporarily switch to a different DB only for these read/write
# actions.
Avram.use_database(CustomDB) do
user = UserQuery.find(1)
SaveUser.update!(user, whatever: true)
SoftDeleteUser.delete(user)
end
# uses the normal ReadDatabase
UserQuery.find(2)I'm thinking that in order to do this, we may need to refactor how the databases are setup. At the moment we use a class as the definition:
def self.read_database : Avram::Database.class
ReadDatabase
endBut this may need to become an instance....
getter read_database : Avram::Database do
ReadDatabase.new
endIf we went with instances everywhere, then we could easily do something like
def self.use_database(db) do
old_db = current_db
current_db = db
yield
current_db = old_db
endThis will need a bit more planning though to make sure it will be thread safe so when multithreadding comes we're ready.
Metadata
Metadata
Assignees
Labels
No labels