Class Index [+]

Quicksearch

Sequel::Postgres::StatementCache::AdapterMethods

Constants

DML_RE

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

Attributes

statement_cache[R]

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

Public Class Methods

extended(c) click to toggle source

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

     # File lib/sequel/extensions/pg_statement_cache.rb, line 231
231:         def self.extended(c)
232:           c.instance_variable_set(:@statement_cache, StatementCache.new(c.sequel_db.opts[:statement_cache_opts] || {}){|name| c.deallocate(name)})
233:         end

Public Instance Methods

deallocate(name) click to toggle source

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

     # File lib/sequel/extensions/pg_statement_cache.rb, line 242
242:         def deallocate(name)
243:           begin
244:             execute("DEALLOCATE #{name}")
245:           rescue PGError
246:             # table probably got removed, just ignore it
247:           end
248:         end
sequel_db() click to toggle source

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.

     # File lib/sequel/extensions/pg_statement_cache.rb, line 237
237:         def sequel_db
238:           @db
239:         end

Private Instance Methods

execute_query(sql, args=nil) click to toggle source

If the sql query string is one we should cache, cache it. If the query already has a related prepared statement with it, execute the prepared statement instead of executing the query normally.

     # File lib/sequel/extensions/pg_statement_cache.rb, line 255
255:         def execute_query(sql, args=nil)
256:           if sql =~ DML_RE
257:             if name = statement_cache.fetch(sql){|stmt_name| sequel_db.log_yield("PREPARE #{stmt_name} AS #{sql}"){prepare(stmt_name, sql)}}
258:               if args
259:                 sequel_db.log_yield("EXECUTE #{name} (#{sql})", args){exec_prepared(name, args)}
260:               else
261:                 sequel_db.log_yield("EXECUTE #{name} (#{sql})"){exec_prepared(name)}
262:               end
263:             else
264:               super
265:             end
266:           else
267:             super
268:           end
269:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.