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.
Some notable difference:
* jdbc doesn't accept hash config?
* jdbc wants postgresql as the adapter name, while pg (sequel)
wants postgres?
DATABASE_CONFIG = if ENV['DATABASE_URL']
config = "#{ENV['DATABASE_URL']}?max_connections=10"
if RUBY_ENGINE == 'jruby'
"jdbc:#{config}"
else
config
end
else
require 'yaml'
require 'erb'
config = YAML.load(
ERB.new(File.read("#{ROOT}/config/database.yaml")).result(binding))
if RUBY_ENGINE == 'jruby'
"jdbc:postgresql://#{config['host']}/#{config['database']}" \
"?user=#{config['user']}&password=#{config['password']}"
else
config
end
end.merge(:after_connect =>
lambda{ |c| c.execute("SET LC_MONETARY TO 'POSIX'")})
--
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.