Skip to content

Loading…

Accept database connection options #18

Closed
wants to merge 2 commits into from

2 participants

@jbalogh

Added a test, let's see what happens when it hits Travis!

@nelhage nelhage closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @jbalogh
  2. @jbalogh

    Inspect the db object

    jbalogh committed
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 12 deletions.
  1. +13 −12 lib/mosql/sql.rb
  2. +8 −0 test/functional/sql.rb
View
25 lib/mosql/sql.rb
@@ -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)
View
8 test/functional/sql.rb
@@ -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.db.pool.max_size, 4)
+ new_adapter = MoSQL::SQLAdapter.new(nil, sql_test_uri, :max_connections => 8)
+ assert_equal(new_adapter.db.pool.max_size, 8)
+ end
+ end
end
Something went wrong with that request. Please try again.