Class: ROM::SQL::ProjectionDSL

Inherits:
DSL
  • Object
show all
Defined in:
lib/rom/sql/projection_dsl.rb

Overview

Projection DSL used in reading API (select, select_append etc.)

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from ROM::SQL::DSL

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ 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.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rom/sql/projection_dsl.rb', line 52

def method_missing(meth, *args, &block)
  if schema.key?(meth)
    schema[meth]
  else
    type = type(meth)

    if type
      if args.empty?
        ::ROM::SQL::Function.new(type, schema: schema)
      else
        ::ROM::SQL::Attribute[type].value(args[0])
      end
    else
      super
    end
  end
end

Instance Method Details

#`(value) ⇒ Attribute

Return a string literal that will be directly used in an SQL statement or query

Examples:

users.select { `'FOO'`.as(:foo) }.first
# => { :foo => "FOO" }

Parameters:

  • value (String)

    A string object

Returns:

  • (Attribute)

    An SQL attribute with a string literal expression



23
24
25
26
# File 'lib/rom/sql/projection_dsl.rb', line 23

def `(value)
  expr = ::Sequel.lit(value)
  ::ROM::SQL::Attribute.new(type(:string)).meta(sql_expr: expr)
end

#function(name, *attrs) ⇒ Rom::SQL::Function Also known as: f

Return a SQL function with value Any

Examples:

users.select { function(:count, :id).as(:total) }

Parameters:

  • name (Symbol)

    SQL function

  • attrs (Symbol)

Returns:

  • (Rom::SQL::Function)


39
40
41
# File 'lib/rom/sql/projection_dsl.rb', line 39

def function(name, *attrs)
  ::ROM::SQL::Function.new(::ROM::Types::Any, schema: schema).public_send(name, *attrs)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

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.

Returns:

  • (Boolean)


45
46
47
# File 'lib/rom/sql/projection_dsl.rb', line 45

def respond_to_missing?(name, include_private = false)
  super || type(name)
end