Skip to content

Commit

Permalink
Accept database connection options
Browse files Browse the repository at this point in the history
  • Loading branch information
jbalogh committed Apr 8, 2013
1 parent 06aca74 commit fa9bb72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/mosql/sql.rb
Expand Up @@ -4,21 +4,22 @@ class SQLAdapter

attr_reader :db

def initialize(schema, uri, pgschema=nil)
def initialize(schema, uri, pgschema=nil, opts={})
@schema = schema
connect_db(uri, pgschema)
connect_db(uri, pgschema, opts)
end

def connect_db(uri, pgschema)
@db = Sequel.connect(uri, :after_connect => proc do |conn|
if pgschema
begin
conn.execute("CREATE SCHEMA \"#{pgschema}\"")
rescue PG::Error
end
conn.execute("SET search_path TO \"#{pgschema}\"")
end
end)
def connect_db(uri, pgschema, opts={})
opts[:after_connect] = proc do |conn|
if pgschema
begin
conn.execute("CREATE SCHEMA \"#{pgschema}\"")
rescue PG::Error
end
conn.execute("SET search_path TO \"#{pgschema}\"")
end
end
@db = Sequel.connect(uri, opts)
end

def table_for_ns(ns)
Expand Down
8 changes: 8 additions & 0 deletions test/functional/sql.rb
Expand Up @@ -35,4 +35,12 @@ class MoSQL::Test::Functional::SQLTest < MoSQL::Test::Functional
assert_equal('blue', @table[:_id => 0][:color])
end
end

describe 'database options' do
it 'can be passed through SQLAdapter' do
assert_equal(@adapter.pool.max_size, 4)
new_adapter = MoSQL::SQLAdapter.new(nil, sql_test_uri, :max_connections => 8)
assert_equal(new_adapter.pool.max_size, 8)
end
end
end

0 comments on commit fa9bb72

Please sign in to comment.