On Tuesday, February 3, 2015 at 12:31:10 PM UTC-8, Lin Jen-Shin wrote:
>
> On Tuesday, February 3, 2015 at 12:40:15 AM UTC+8, Jeremy Evans wrote:
> > You can do this via using an :after_connect proc, which is passed each
> newly created connection object before it is used by Sequel.
> >
> > DB = Sequel.connect(..., :after_connect=>proc{|c| c.execute("SET
> LC_MONETARY TO 'POSIX'")})
> >
> > Note that c in this case is the connection object, so you need to use
> the API of the underlying driver. The above example will work for the pg
> and postgres-pr drivers, the jdbc driver will require something different.
> >
> > Thanks,
> > Jeremy
>
> Great, thank you!
>
> Since you mentioned jdbc, currently we have a painful config like this:
> Is there any way to improve this? I could totally understand that the
> advantage of passing the database URL string along to jdbc, but it's
> really painful to write something like this if we want to make sure it
> works both on pg and jdbc-postgres.
>
I think it would be simpler if you used the same connection string for
both, with just the first part being different:
scheme = RUBY_ENGINE == 'jruby' ? 'jdbc:postgresql' : 'postgres'
"#{scheme}://#{config['host']}/#{config['database']}?user=#{config['user']}&password=#{config['password']}"
> Some notable difference:
>
> * jdbc doesn't accept hash config?
>
Correct. The Sequel jdbc adapter passes the connection string directly to
JDBC. This is different than most other adapters, which will take a
connection string and turn it into an options hash.
> * jdbc wants postgresql as the adapter name, while pg (sequel)
> wants postgres?
>
Yep, blame JDBC for that.
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.