Module: Sequel::Dataset::ArgumentMapper

Included in:
UnnumberedArgumentMapper, Postgres::Dataset::ArgumentMapper, SQLite::Dataset::ArgumentMapper
Defined in:
lib/sequel/lib/sequel/dataset/prepared_statements.rb

Overview

Default implementation of the argument mapper to allow native database support for bind variables and prepared statements (as opposed to the emulated ones used by default).

Constant Summary

SQL_QUERY_TYPE =
Hash.new{|h,k| h[k] = k}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bind_argumentsObject

The bind arguments to use for running this prepared statement



16
17
18
# File 'lib/sequel/lib/sequel/dataset/prepared_statements.rb', line 16

def bind_arguments
  @bind_arguments
end

#prepared_statement_nameObject

The name of the prepared statement, if any.



13
14
15
# File 'lib/sequel/lib/sequel/dataset/prepared_statements.rb', line 13

def prepared_statement_name
  @prepared_statement_name
end

Instance Method Details

#call(hash, &block) ⇒ Object

Set the bind arguments based on the hash and call super.



19
20
21
22
23
24
25
# File 'lib/sequel/lib/sequel/dataset/prepared_statements.rb', line 19

def call(hash, &block)
  ds = clone
  ds.prepared_sql
  ds.bind_arguments = ds.map_to_prepared_args(hash)
  ds.prepared_args = hash
  ds.run(&block)
end

#prepared_sqlObject

Override the given *_sql method based on the type, and cache the result of the sql.



29
30
31
32
33
34
35
# File 'lib/sequel/lib/sequel/dataset/prepared_statements.rb', line 29

def prepared_sql
  return @prepared_sql if @prepared_sql
  @prepared_args ||= []
  @prepared_sql = super
  meta_def("#{sql_query_type}_sql"){|*args| prepared_sql}
  @prepared_sql
end