Class: TwoWaySQL::MergeResult

Inherits:
Object
  • Object
show all
Defined in:
lib/twowaysql/template.rb

Overview

TwoWaySQL::MergeResult represents merge result of template and data. it contains SQL string with placeholders, and bound variables associated with placeholders.

Usage

merged = template.merge(:job => "MANAGER", :deptno => 30)
merged.sql                #=> "SELECT * FROM emp WHERE job = ? AND deptno = ?"
merged.bound_variables    #=> ["MANAGER", 30]

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ MergeResult

Returns a new instance of MergeResult.



72
73
74
# File 'lib/twowaysql/template.rb', line 72

def initialize(context)
  @context = context
end

Instance Method Details

#bound_variablesObject Also known as: vars

return array of variables which indices are corresponding to placeholders. alias ‘vars’ is available for short-hand.

Return

array of bound variables



91
92
93
# File 'lib/twowaysql/template.rb', line 91

def bound_variables
  @context.bound_variables
end

#sqlObject

return merge result SQL with placeholders (question mark).

Return

merge result SQL with placeholders



81
82
83
# File 'lib/twowaysql/template.rb', line 81

def sql
  @context.sql
end