Class: ROM::SQL::DSL Private

Inherits:
BasicObject
Defined in:
lib/rom/sql/dsl.rb

Overview

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.

API:

  • private

Direct Known Subclasses

GroupDSL, OrderDSL, ProjectionDSL, RestrictionDSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ DSL

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 a new instance of DSL.

API:

  • private



24
25
26
27
28
# File 'lib/rom/sql/dsl.rb', line 24

def initialize(schema)
  @schema = schema
  @relations = schema.respond_to?(:relations) ? schema.relations : EMPTY_HASH
  @picked_relations = ::Concurrent::Map.new
end

Instance Attribute Details

#picked_relationsObject (readonly)

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



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

def picked_relations
  @picked_relations
end

#relationsObject (readonly)

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



17
18
19
# File 'lib/rom/sql/dsl.rb', line 17

def relations
  @relations
end

#schemaObject (readonly)

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



13
14
15
# File 'lib/rom/sql/dsl.rb', line 13

def schema
  @schema
end

Instance Method Details

#`(value) ⇒ Sequel::LiteralString

Return a string literal that will be used directly in an ORDER clause

Parameters:

Returns:

API:

  • public



54
55
56
# File 'lib/rom/sql/dsl.rb', line 54

def `(value)
  ::Sequel.lit(value)
end

#call(&block) ⇒ 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.

API:

  • private



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rom/sql/dsl.rb', line 31

def call(&block)
  arg, kwargs = select_relations(block.parameters)

  if kwargs.nil?
    result = instance_exec(arg, &block)
  else
    result = instance_exec(**kwargs, &block)
  end

  if result.is_a?(::Array)
    result
  else
    [result]
  end
end

#exists(relation) ⇒ Object

Returns a result of SQL EXISTS clause.

Examples:

users.where { exists(users.where(name: 'John')) }
users.select_append { |r|
  exists(r[:posts].where(r[:posts][:user_id] => id)).as(:has_posts)
}

API:

  • public



67
68
69
# File 'lib/rom/sql/dsl.rb', line 67

def exists(relation)
  ::ROM::SQL::Attribute[Types::Bool].meta(sql_expr: relation.dataset.exists)
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



72
73
74
# File 'lib/rom/sql/dsl.rb', line 72

def respond_to_missing?(name, include_private = false)
  super || schema.key?(name)
end