Class TwoWaySQL::Template
In: lib/twowaysql/template.rb
Parent: Object

TwoWaySQL::Template represents template object, acts as a Facade for this package. Template is stateless, reentrant object so template object is cacheable.

Methods

merge   new   parse  

Public Class methods

parse TwoWaySQL-style SQL then return TwoWaySQL::Template object

Usage

  sql = "SELECT * FROM emp WHERE job = /*ctx[:job]*/'CLERK' AND deptno = /*ctx[:deptno]*/20"
  template = TwoWaySQL::Template.parse(sql)

Arguments

sql_io:IO-like object that contains TwoWaySQL-style SQL
opts:(optional) Hash of parse options to pass internal lexer. default is empty hash.

Return

TwoWaySQL::Template object that represents parse result

Public Instance methods

merge data with template

Usage

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

Arguments

data:Hash-like object that contains data to merge. This data will evaluated as name ‘ctx’.

Return

TwoWaySQL::MergeResult object that represents merge result

[Validate]