On Sunday, April 8, 2018 at 5:05:39 PM UTC-7, Greg Gilbert wrote: > > Hey, > > Following up on my last message (which I closed myself), I'm looking to > create a class that extends Sequel::Model and uses the schema in a > connection. > > Here's an example: > > MyDB = Sequel.connect( > adapter: 'postgres', > host: ENV['MYDB_HOST'], > port: ENV['MYDB_PORT'], > database: ENV['MYDB_DATABASE'], > user: ENV['MYDB_USERNAME'], > password: ENV['MYDB_PASSWORD'] > ) > > Then, when trying to define the class using that connection: > > class Account < Sequel::Model(MyDB[:foo][:account]) > > This doesn't work. This does, however: > > class Account < Sequel::Model(Sequel[:foo][:account]) > > It seems dangerous to not specify the connection to use. Is there a way to > do this to ensure that the data is correct? >
You first example doesn't work because ,MyDB[:foo] returns a dataset (SELECT * FROM foo), so your code Dataset#[], which issues a query to the database (SELECT * FROM foo WHERE account LIMIT 1) and returns the first row. Your second example is correct but doesn't specify a database to use, so Sequel::Model.db will be used by default, and the default for that is the first Database instance created (first entry in Sequel::DATABASES). You probably want: class Account < Sequel::Model(MyDB[Sequel[:foo][:account]]); end # or: class Account < Sequel::Model(MyDB.from{foo[:account]}); end Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.