Module: Sequel::Postgres::StatementCache::AdapterMethods

Defined in:
lib/sequel/extensions/pg_statement_cache.rb

Constant Summary collapse

DML_RE =

A regular expression for the types of queries to cache. Any queries not matching this regular expression are not cached.

/\A(WITH|SELECT|INSERT|UPDATE|DELETE) /

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#statement_cacheObject (readonly)

The StatementCache instance for this connection. Note that each connection has a separate StatementCache, because prepared statements are connection-specific.



227
228
229
# File 'lib/sequel/extensions/pg_statement_cache.rb', line 227

def statement_cache
  @statement_cache
end

Class Method Details

.extended(c) ⇒ Object

Set the statement_cache for the connection, using the database’s :statement_cache_opts option.



231
232
233
# File 'lib/sequel/extensions/pg_statement_cache.rb', line 231

def self.extended(c)
  c.instance_variable_set(:@statement_cache, StatementCache.new(c.sequel_db.opts[:statement_cache_opts] || {}){|name| c.deallocate(name)})
end

Instance Method Details

#deallocate(name) ⇒ Object

Deallocate on the server the prepared statement with the given name.



242
243
244
245
246
247
248
# File 'lib/sequel/extensions/pg_statement_cache.rb', line 242

def deallocate(name)
  begin
    execute("DEALLOCATE #{name}")
  rescue PGError
    # table probably got removed, just ignore it
  end
end

#sequel_dbObject

pg seems to already use the db method (but not the @db instance variable), so use the sequel_db method to access the related Sequel::Database object.



237
238
239
# File 'lib/sequel/extensions/pg_statement_cache.rb', line 237

def sequel_db
  @db
end