On Jul 13, 3:06 am, Piotr Szotkowski <[email protected]> wrote: > Hi, I’m a newbie Sequel user, trying to learn it while developing > a small application (email signature > manager/randomiser):http://github.com/Chastell/signore > > I’m sorry if this question was raised before (or is a common knowledge), > I’m on my honeymoon and have very sporadic net access – hence can’t > google as much as I’d want to. :|
I recommend a reevaluation of your priorities. :) > My problem is that (a) model definition seems to require an established > database connection and (b) the defined models seem to be tied > (data-wise) to the database they were defined for, even if I switch > connections later. Yes. This behavior is by design. Models use the database connection you have defined to get the columns/schema for the model's table/ dataset, so the database connection needs to exist first. You can set which database to use by default: Sequel::Model.db = ... You can also set which database to use for each model: class Foo < Sequel::Model(DB1[:foos]) end class Bar < Sequel::Model(DB2[:bars]) end > The second problem can be observed in my application’s > specs:http://github.com/Chastell/signore/blob/ee43252614f14b55a503694cd5005... > – even though I (seemingly?) reconnect to a :memory: database > in the last two specs, the data from them are being put in the > spec/fixtures/example.db database. > > The first problem means I have to use an ugly hack to even > require the model files – the Singore.define_models method > inhttp://github.com/Chastell/signore/blob/ee43252614f14b55a503694cd5005... > > Any help on (a) how to define models without having to tie them to > a given database and/or (b) how to sanely switch databases with the > models switching over would be most appreciated. I'd recommend just requiring your models after setting up your database connections, and making sure each model uses the correct database so you don't have to switch the databases afterward. If you are thinking about switching a model's database during the running of the app, I advise you to reconsider. If you really want to do that, create a subclass for each model for each database. > Again, apologies if I’m (hopefully!) missing something > obvious; this is my first Sequel/Amalgalite app. If you find the Amalgalite adapter is a bit slow, you may want to try the SQLite adapter. I know that the SQLite adapter is much faster when running the specs. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
