Class: Ensql::SequelAdapter
- Inherits:
-
Object
- Object
- Ensql::SequelAdapter
- Extended by:
- Forwardable
- Includes:
- Adapter
- Defined in:
- lib/ensql/sequel_adapter.rb
Overview
Wraps a Sequel::Database to implement the Adapter interface for Sequel. You may want to utilize the relevant Sequel extensions to make the most of database-specific deserialization and other features. By default, uses the first database in Sequel::Databases. Other databases can be passed to the constructor.
require 'sequel'
DB = Sequel.connect('postgres://localhost/mydb')
DB.extend(:pg_json)
Ensql.adapter = Ensql::SequelAdapter.new(DB)
To stream rows, configure streaming on the connection and use Ensql::SQL#each_row
DB = Sequel.connect('postgresql:/')
DB.extension(:pg_streaming)
DB.stream_all_queries = true
Ensql.adapter = Ensql::SequelAdapter.new(DB)
Ensql.sql("select * from large_table").each_row do |row|
# This now yields each row in single-row mode.
# The connection cannot be used for other queries while this is streaming.
end
Class Method Summary collapse
-
.pool(db) ⇒ PoolWrapper
Wrap the raw connections from a Sequel::Database connection pool.
Instance Method Summary collapse
-
#initialize(db = first_configured_database) ⇒ SequelAdapter
constructor
A new instance of SequelAdapter.
Methods included from Adapter
#fetch_first_column, #fetch_first_field, #fetch_first_row
Constructor Details
#initialize(db = first_configured_database) ⇒ SequelAdapter
Returns a new instance of SequelAdapter.
65 66 67 |
# File 'lib/ensql/sequel_adapter.rb', line 65 def initialize(db = first_configured_database) @db = db end |
Class Method Details
.pool(db) ⇒ PoolWrapper
Wrap the raw connections from a Sequel::Database connection pool. This allows us to safely checkout the underlying database connection for use in a database specific adapter.
Ensql.adapter = MySqliteAdapter.new(SequelAdapter.pool)
58 59 60 61 62 |
# File 'lib/ensql/sequel_adapter.rb', line 58 def self.pool(db) PoolWrapper.new do |client_block| db.pool.hold(&client_block) end end |