Created
February 24, 2010 11:26
-
-
Save bosko/313340 to your computer and use it in GitHub Desktop.
List Databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'activerecord-sqlserver-adapter' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlserver', | |
:mode => 'ODBC', | |
:host => '<server>', | |
:username => '<user_name>', | |
:password => '<pass>' | |
:dsn => '<odbc_dsn_name>' | |
) | |
databases = ActiveRecord::Base.connection.select_all('select name from sys.databases') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "active_record" | |
require 'logger' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'postgresql', | |
:database => '<db_name>', | |
:username => '<user>', | |
:password => '<pass>', | |
:host => '/var/run/postgresql') | |
ActiveRecord::Base.logger = Logger.new('logfile.txt') | |
databases = ActiveRecord::Base.connection.query("select datname from pg_database") | |
#=> [["template1"], ["template0"], ["postgres"], ["testdb"]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment