module GxG::Database
Public Class Methods
connect(the_url, options={})
click to toggle source
# File lib/gxg/gxg_database.rb, line 10 def self.connect(the_url, options={}) # TODO: require :credential (access privs) result = nil begin # check for URI ipv6 [format] compatibility db_url = ::URI::parse(the_url.to_s) the_path = db_url.path.to_s if the_path == "" the_path = db_url.hostname.to_s end if ::RUBY_ENGINE == "jruby" case db_url.scheme.to_sym when :sqlite, :sqlite3 if ["/memory", "memory"].include?(the_path) result = Sequel.connect("jdbc:sqlite::memory:") else result = Sequel.connect("jdbc:sqlite:" + the_path) end else result = Sequel.connect({:adapter => ("jdbc:" + db_url.scheme.to_s), :host => (db_url.hostname.to_s), :database => (db_url.path.to_s.split("/").last), :user => (db_url.user.to_s), :password => (db_url.password.to_s)}) end # else case db_url.scheme.to_sym when :sqlite, :sqlite3 if ["/memory", "memory"].include?(the_path) result = Sequel.connect("sqlite::memory:") else result = Sequel.connect("sqlite://" + the_path) end else # auto-forward to mysql2 gem if mysql:// scheme if db_url.scheme.to_s == "mysql" # result = Sequel.connect({:adapter => "mysql2", :host => (db_url.hostname.to_s), :database => (db_url.path.to_s.split("/").last), :user => (db_url.user.to_s), :password => (db_url.password.to_s)}) # else # result = Sequel.connect({:adapter => (db_url.scheme.to_s), :host => (db_url.hostname.to_s), :database => (db_url.path.to_s.split("/").last), :user => (db_url.user.to_s), :password => (db_url.password.to_s)}) # end end end result = ::GxG::Database::Database.new(result, options.merge({:url => (db_url)})) rescue => the_error log_error({:error => the_error, :parameters => {:url => (the_url), :options => (options)}}) end result end