Class: ActiveRecord::Refined::AST::Sql

Inherits:
Node
  • Object
show all
Includes:
Arithmetics, Connectives, Predications
Defined in:
lib/active_record/refined/ast.rb

Overview

SQL as written: sql("length(name) > ?", 10). The ? and :name placeholders take quoted values through sanitize_sql_array, which needs the connection, so the binds wait here until the model is known. Without binds the statement passes untouched -- which is what leaves PostgreSQL's ? operators writable, since only the positional-bind rewrite reads ? as a placeholder.

As an operand the statement is parenthesized: its precedence is whatever was written inside. The top of a select list gets it bare, through field_arel, where parentheses would refuse an alias written into the string.

Instance Method Summary collapse

Methods included from Connectives

#!, #&, #|

Methods included from Arithmetics

#&, #*, #+, #-, #/, #<<, #>>, #^, #bitwise_and, #bitwise_not, #bitwise_or, #bitwise_xor, #|, #~

Methods included from Predications

#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_text, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #keys, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

#initialize(statement, binds) ⇒ Sql

Returns a new instance of Sql.



827
828
829
830
831
832
833
834
# File 'lib/active_record/refined/ast.rb', line 827

def initialize(statement, binds)
  unless statement.is_a?(::String)
    raise ArgumentError,
      "sql takes the statement as a string, not #{statement.inspect}"
  end
  @statement = statement
  @binds = binds
end