Get PG Database Names in IRB using Sequel

Hi folks.

I need to get a list of schemas (databases) in Postgresql using Sequel. My client can perform the SQL, but for some reason, my connection in IRB doesn’t want see anything.

require ‘sequel’
require ‘pg’
d = Sequel.connect('postgres://dingbat:password@0.0.0.0/postgres')
r = d.run('select datname, datistemplate from pg_database where datistemplate = false’)
puts r.inspect # => nil

Any workarounds that anybody knows about? I appreciate any input.

Cheers, Bee

Hi.
It seems like run method is used just to execute SQL. It doesn't provide
you with a result since the method always explicit returns nil (see here
<sequel/lib/sequel/database/query.rb at master · jeremyevans/sequel · GitHub;
).
You can use a dataset like

DB = Sequel.connect('postgres://dingbat:password@0.0.0.0/postgres')
databases = DB['select datname, datistemplate from pg_database where
datistemplate = false']
databases.each { |db| p db }

···

2016-09-30 2:32 GMT+03:00 Bee.Lists <bee.lists@gmail.com>:

Hi folks.

I need to get a list of schemas (databases) in Postgresql using Sequel.
My client can perform the SQL, but for some reason, my connection in IRB
doesn’t want see anything.

require ‘sequel’
require ‘pg’
d = Sequel.connect('postgres://dingbat:password@0.0.0.0/postgres')
r = d.run('select datname, datistemplate from pg_database where
datistemplate = false’)
puts r.inspect # => nil

Any workarounds that anybody knows about? I appreciate any input.

Cheers, Bee

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Exactly along the lines of which I was ‘using’, but IRB is my first go-to and it was closed. My postgresql client showed otherwise. So that’s the confusion.

databases.size # => nil

Confusing.

Anyway, I hard coded the database (schema) names, and all is good.

Thanks

···

On Sep 30, 2016, at 1:28 AM, Aleksey Ivanov <ialexxei@gmail.com> wrote:

DB = Sequel.connect('postgres://dingbat:password@0.0.0.0/postgres')
databases = DB['select datname, datistemplate from pg_database where datistemplate = false']
databases.each { |db| p db }

Cheers, Bee