Jaguar-dart / jaguar_orm

Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
https://jaguar-dart.github.io
BSD 3-Clause "New" or "Revised" License
217 stars 52 forks source link

add switch database method sqflite adapter #72

Closed jaumard closed 6 years ago

jaumard commented 6 years ago

Little story about this :)

In our app we need one database per user, so each time there a login we need to switch the database to another one. Problem with the current way of working of jaguar is that the Apater is needed in every "Bean" so if we want to switch database we need to switch Adapter, meaning recreate every "Bean" that are in multiple place of the app... so it's not really doable/safe to switch the adapter as reference can be kept in other objects. Instead what we can if switch the underlying connection to a new one each time the user login. That why switchDatabase is useful

tejainece commented 6 years ago

Hi,

Adapter is immutable. You have to maintain a connection per user resulting in one adapter per connection which in turn resulting in a bean per connection.

jaumard commented 6 years ago

Hum that will not work for me... it will basically be equal to just restart the app from scratch for each user... Bean are not singleton so you can have references of them everywhere in the app... only way you're sure there no reference in some redux middleware it to restart from scratch... One way that I could achieve that on my side would be to change the internal use of _connexion to the public getter "connection". Like this it will allow my to override the adapter and do this switchDatabase.

Is that changes ok for you then ?

jaumard commented 6 years ago

just pushed that changes and remove switchDatabase, let me know if it's ok for you like this @tejainece :) I'll do it on my side