class ActiveRecord::StatementCache
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/active_record/statement_cache.rbs class ActiveRecord::StatementCache def execute: ((Array[Integer] | Array[String]) params, ActiveRecord::ConnectionAdapters::PostgreSQLAdapter connection, ) -> untyped end
:nodoc:
cache.execute([“my book”], Book.connection)
And pass the bind values as the first argument of execute
call.
end
Book.where(name: params.bind)
cache = StatementCache.create(Book.connection) do |params|
block parameter.
If you want to cache the statement without the values you can use the bind
method of the
call the cached relation gets duped. Database is queried when to_a
is called on the relation.
The relation returned by the block is cached, and for each
cache.execute([], Book.connection)
method:
The cached statement is executed by using the
end
Book.where(name: “my book”).where(“author_id > 3”)
cache = StatementCache.create(Book.connection) do |params|
Initializing the cache is done by passing the statement in the create block:
Statement cache is used to cache a single statement in order to avoid creating the AST again.
def self.create(connection, callable = nil, &block)
def self.create(connection, callable = nil, &block) relation = (callable || block).call Params.new query_builder, binds = connection.cacheable_query(self, relation.arel) bind_map = BindMap.new(binds) new(query_builder, bind_map, relation.klass) end
def self.partial_query(values)
def self.partial_query(values) PartialQuery.new(values) end
def self.partial_query_collector
def self.partial_query_collector PartialQueryCollector.new end
def self.query(sql)
def self.query(sql) Query.new(sql) end
def self.unsupported_value?(value)
def self.unsupported_value?(value) case value when NilClass, Array, Range, Hash, Relation, Base then true end end
def execute(params, connection, &block)
Experimental RBS support (using type sampling data from the type_fusion
project).
def execute: ( params, ActiveRecord::ConnectionAdapters::PostgreSQLAdapter connection, ) -> untyped
This signature was generated using 2 samples from 1 application.
def execute(params, connection, &block) bind_values = bind_map.bind params sql = query_builder.sql_for bind_values, connection klass.find_by_sql(sql, bind_values, preparable: true, &block) rescue ::RangeError [] end
def initialize(query_builder, bind_map, klass)
def initialize(query_builder, bind_map, klass) @query_builder = query_builder @bind_map = bind_map @klass = klass end