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.)

API:

  • public

Instance Attribute Summary

Attributes inherited from DSL

#picked_relations, #relations, #schema

Instance Method Summary collapse

Methods inherited from DSL

#call, #exists, #initialize

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.

API:

  • private



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

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:

  • A string object

Returns:

  • An SQL attribute with a string literal expression

API:

  • public



21
22
23
24
# File 'lib/rom/sql/projection_dsl.rb', line 21

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:

  • SQL function

Returns:

API:

  • public



37
38
39
# File 'lib/rom/sql/projection_dsl.rb', line 37

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:

API:

  • private



43
44
45
# File 'lib/rom/sql/projection_dsl.rb', line 43

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