Module: Arel

Defined in:
lib/arel/crud.rb,
lib/arel.rb,
lib/arel/math.rb,
lib/arel/table.rb,
lib/arel/errors.rb,
lib/arel/nodes/in.rb,
lib/arel/visitors.rb,
lib/arel/nodes/and.rb,
lib/arel/nodes/cte.rb,
lib/arel/nodes/case.rb,
lib/arel/nodes/node.rb,
lib/arel/nodes/over.rb,
lib/arel/nodes/true.rb,
lib/arel/nodes/with.rb,
lib/arel/expressions.rb,
lib/arel/nodes/count.rb,
lib/arel/nodes/false.rb,
lib/arel/nodes/unary.rb,
lib/arel/nodes/binary.rb,
lib/arel/nodes/casted.rb,
lib/arel/nodes/filter.rb,
lib/arel/nodes/regexp.rb,
lib/arel/nodes/window.rb,
lib/arel/predications.rb,
lib/arel/tree_manager.rb,
lib/arel/visitors/dot.rb,
lib/arel/nodes/comment.rb,
lib/arel/nodes/extract.rb,
lib/arel/nodes/matches.rb,
lib/arel/delete_manager.rb,
lib/arel/insert_manager.rb,
lib/arel/nodes/equality.rb,
lib/arel/nodes/function.rb,
lib/arel/nodes/grouping.rb,
lib/arel/nodes/ordering.rb,
lib/arel/nodes/terminal.rb,
lib/arel/select_manager.rb,
lib/arel/update_manager.rb,
lib/arel/visitors/mysql.rb,
lib/arel/collectors/bind.rb,
lib/arel/factory_methods.rb,
lib/arel/nodes/ascending.rb,
lib/arel/nodes/fragments.rb,
lib/arel/visitors/sqlite.rb,
lib/arel/visitors/to_sql.rb,
lib/arel/nodes/bind_param.rb,
lib/arel/nodes/descending.rb,
lib/arel/nodes/inner_join.rb,
lib/arel/nodes/outer_join.rb,
lib/arel/visitors/visitor.rb,
lib/arel/alias_predication.rb,
lib/arel/nodes/join_source.rb,
lib/arel/nodes/select_core.rb,
lib/arel/nodes/sql_literal.rb,
lib/arel/nodes/string_join.rb,
lib/arel/nodes/table_alias.rb,
lib/arel/nodes/values_list.rb,
lib/arel/nodes/leading_join.rb,
lib/arel/order_predications.rb,
lib/arel/filter_predications.rb,
lib/arel/visitors/postgresql.rb,
lib/arel/window_predications.rb,
lib/arel/attributes/attribute.rb,
lib/arel/collectors/composite.rb,
lib/arel/nodes/homogeneous_in.rb,
lib/arel/nodes/named_function.rb,
lib/arel/collectors/sql_string.rb,
lib/arel/nodes/full_outer_join.rb,
lib/arel/nodes/infix_operation.rb,
lib/arel/nodes/node_expression.rb,
lib/arel/nodes/unary_operation.rb,
lib/arel/nodes/delete_statement.rb,
lib/arel/nodes/insert_statement.rb,
lib/arel/nodes/right_outer_join.rb,
lib/arel/nodes/select_statement.rb,
lib/arel/nodes/update_statement.rb,
lib/arel/collectors/plain_string.rb,
lib/arel/nodes/bound_sql_literal.rb,
lib/arel/nodes/unqualified_column.rb,
lib/arel/collectors/substitute_binds.rb

Overview

:nodoc: all

Defined Under Namespace

Modules: AliasPredication, Attributes, Collectors, Crud, Expressions, FactoryMethods, FilterPredications, Math, Nodes, OrderPredications, Predications, Visitors, WindowPredications Classes: ArelError, BindError, DeleteManager, EmptyJoinError, InsertManager, SelectManager, Table, TreeManager, UpdateManager

Constant Summary collapse

VERSION =
"10.0.0"
Attribute =
Attributes::Attribute

Class Method Summary collapse

Class Method Details

.arel_node?(value) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


60
61
62
# File 'lib/arel.rb', line 60

def self.arel_node?(value) # :nodoc:
  value.is_a?(Arel::Nodes::Node) || value.is_a?(Arel::Attribute) || value.is_a?(Arel::Nodes::SqlLiteral)
end

.fetch_attribute(value, &block) ⇒ Object

:nodoc:



64
65
66
67
68
# File 'lib/arel.rb', line 64

def self.fetch_attribute(value, &block) # :nodoc:
  unless String === value
    value.fetch_attribute(&block)
  end
end

.sql(sql_string, *positional_binds, **named_binds) ⇒ Object

Wrap a known-safe SQL string for passing to query methods, e.g.

Post.order(Arel.sql("REPLACE(title, 'misc', 'zzzz') asc")).pluck(:id)

Great caution should be taken to avoid SQL injection vulnerabilities. This method should not be used with unsafe values such as request parameters or model attributes.

Take a look at the security guide for more information.

To construct a more complex query fragment, including the possible use of user-provided values, the sql_string may contain ? and :key placeholders, corresponding to the additional arguments. Note that this behavior only applies when bind value parameters are supplied in the call; without them, the placeholder tokens have no special meaning, and will be passed through to the query as-is.



48
49
50
51
52
53
54
# File 'lib/arel.rb', line 48

def self.sql(sql_string, *positional_binds, **named_binds)
  if positional_binds.empty? && named_binds.empty?
    Arel::Nodes::SqlLiteral.new sql_string
  else
    Arel::Nodes::BoundSqlLiteral.new sql_string, positional_binds, named_binds
  end
end

.starObject

:nodoc:



56
57
58
# File 'lib/arel.rb', line 56

def self.star # :nodoc:
  sql "*"
end