lib/duckdb/database.rb in duckdb-0.2.7.0 vs lib/duckdb/database.rb in duckdb-0.2.8.0

- old
+ new

@@ -19,10 +19,11 @@ # p row # end # class Database private_class_method :_open + private_class_method :_open_ext if defined?(DuckDB::Config) class << self ## # Opens database. # The first argument is DuckDB database file path to open. @@ -36,17 +37,29 @@ # DuckDB::Database.open do |db| # con = db.connect # con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))') # end # - def open(*args) - db = _open(*args) + def open(dbpath = nil, config = nil) + db = _db_open(dbpath, config) return db unless block_given? begin yield db ensure db.close + end + end + + private + + def _db_open(dbpath, config) + if defined?(DuckDB::Config) && config + _open_ext(dbpath, config) + elsif config + _open(dbpath, config) + else + _open(dbpath) end end end ##