Class: Ensql::PostgresAdapter
- Inherits:
-
Object
- Object
- Ensql::PostgresAdapter
- Includes:
- Adapter
- Defined in:
- lib/ensql/postgres_adapter.rb
Overview
Wraps a pool of PG connections to implement the Adapter interface. The adapter can use a 3rd-party pool (e.g. from ActiveRecord of Sequel) or manage its own using the simple connection_pool gem.
This adapter is much faster and offers much better PostgreSQL specific parameter interpolation than the framework adapters.
Class Method Summary collapse
-
.pool(**pool_opts, &connection_block) ⇒ Object
Set up a connection pool using the supplied block to initialise connections.
Instance Method Summary collapse
-
#initialize(pool) ⇒ PostgresAdapter
constructor
A new instance of PostgresAdapter.
Constructor Details
#initialize(pool) ⇒ PostgresAdapter
Returns a new instance of PostgresAdapter.
49 50 51 52 53 54 |
# File 'lib/ensql/postgres_adapter.rb', line 49 def initialize(pool) @pool = pool @quoter = PG::TextEncoder::QuotedLiteral.new @result_type_map = @pool.with { |c| PG::BasicTypeMapForResults.new(c) } @query_type_map = @pool.with { |c| build_query_type_map(c) } end |
Class Method Details
.pool(**pool_opts, &connection_block) ⇒ Object
Set up a connection pool using the supplied block to initialise connections.
PostgresAdapter.pool(size: 20) { PG.connect ENV['DATABASE_URL'] }
44 45 46 |
# File 'lib/ensql/postgres_adapter.rb', line 44 def self.pool(**pool_opts, &connection_block) new ConnectionPool.new(**pool_opts, &connection_block) end |