class ROM::SQL::ProjectionDSL

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

@api public

Public Instance Methods

`(value) click to toggle source

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

@example

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

@param [String] value A string object

@return [Attribute] An SQL attribute with a string literal expression

@api public

# 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
f(name, *attrs)
Alias for: function
function(name, *attrs) click to toggle source

Return a SQL function with value `Any`

@example

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

@param [Symbol] name SQL function @param [Symbol] attrs

@return [Rom::SQL::Function]

@api public

# 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
Also aliased as: f
respond_to_missing?(name, include_private = false) click to toggle source

@api private

Calls superclass method ROM::SQL::DSL#respond_to_missing?
# File lib/rom/sql/projection_dsl.rb, line 45
def respond_to_missing?(name, include_private = false)
  super || type(name)
end

Private Instance Methods

method_missing(meth, *args, &block) click to toggle source

@api private

Calls superclass method
# 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