Class: Sequel::Unbinder

Inherits:
ASTTransformer show all
Defined in:
lib/sequel/ast_transformer.rb

Overview

Unbinder is used to take a dataset filter and return a modified version that unbinds already bound values and returns a dataset with bound value placeholders and a hash of bind values. You can then prepare the dataset and use the bound variables to execute it with the same values.

This class only does a limited form of unbinding where the variable names and values can be associated unambiguously. The only cases it handles are <tt>SQL::ComplexExpression<tt> with an operator in UNBIND_OPS, a first argument that’s an instance of a member of UNBIND_KEY_CLASSES, and a second argument that’s an instance of a member of UNBIND_VALUE_CLASSES.

So it can handle cases like:

DB.filter(:a=>1).exclude(:b=>2).where{c > 3}

But it cannot handle cases like:

DB.filter(:a + 1 < 0)

Constant Summary collapse

UNBIND_OPS =

The <tt>SQL::ComplexExpression<tt> operates that will be considered for transformation.

[:'=', :'!=', :<, :>, :<=, :>=]
UNBIND_KEY_CLASSES =

The key classes (first argument of the ComplexExpression) that will considered for transformation.

[Symbol, SQL::Identifier, SQL::QualifiedIdentifier]
UNBIND_VALUE_CLASSES =

The value classes (second argument of the ComplexExpression) that will be considered for transformation.

[Numeric, String, Date, Time]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ASTTransformer

#transform

Constructor Details

#initializeUnbinder

Intialize an empty binds hash.



154
155
156
# File 'lib/sequel/ast_transformer.rb', line 154

def initialize
  @binds = {}
end

Instance Attribute Details

#bindsObject (readonly)

The hash of bind variables that were extracted from the dataset filter.



151
152
153
# File 'lib/sequel/ast_transformer.rb', line 151

def binds
  @binds
end