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 Attribute Summary

Attributes inherited from DSL

#relations, #schema

Instance Method Summary collapse

Methods inherited from DSL

#call, #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.



50
51
52
53
54
55
56
57
58
59
60
61
62
# 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
      ::ROM::SQL::Function.new(type, schema: schema)
    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



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, attr) ⇒ 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

  • attr (Symbol)

Returns:

  • (Rom::SQL::Function)


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

def function(name, attr)
  ::ROM::SQL::Function.new(::ROM::Types::Any, schema: schema).public_send(name, attr)
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)


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

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