Class: ROM::SQL::Function Private

Inherits:
ROM::Schema::Attribute
  • Object
show all
Defined in:
lib/rom/sql/function.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rom/sql/function.rb', line 50

def method_missing(meth, *args)
  if func
    if func.respond_to?(meth)
      meta(func: func.__send__(meth, *args))
    else
      super
    end
  else
    meta(func: Sequel::SQL::Function.new(meth.to_s.upcase, *args))
  end
end

Instance Method Details

#cast(expr, db_type) ⇒ ROM::SQL::Attribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert an expression result to another data type

Examples:

users.select { bool::cast(json_data.get_text('activated'), :boolean).as(:activated) }

Parameters:

  • expr (ROM::SQL::Attribute)

    Expression to be cast

  • db_type (String)

    Target database type

Returns:



40
41
42
# File 'lib/rom/sql/function.rb', line 40

def cast(expr, db_type)
  Attribute[type].meta(sql_expr: ::Sequel.cast(expr, db_type))
end

#is(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/rom/sql/function.rb', line 25

def is(other)
  ::Sequel::SQL::BooleanExpression.new(:'=', func, other)
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/rom/sql/function.rb', line 15

def name
  meta[:alias] || super
end

#qualifiedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
# File 'lib/rom/sql/function.rb', line 19

def qualified
  meta(
    func: ::Sequel::SQL::Function.new(func.name, *func.args.map { |arg| arg.respond_to?(:qualified) ? arg.qualified : arg })
  )
end

#sql_literal(ds) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
10
11
12
13
# File 'lib/rom/sql/function.rb', line 7

def sql_literal(ds)
  if name
    ds.literal(func.as(name))
  else
    ds.literal(func)
  end
end