class ROM::SQL::DSL
@api private
Attributes
picked_relations[R]
@!attribute [r] picked_relations
@return [Concurrent::Map]
relations[R]
@!attribute [r] relations
@return [Hash, RelationRegistry]
schema[R]
@!attribute [r] schema
@return [SQL::Schema]
Public Class Methods
new(schema)
click to toggle source
@api private
# 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
Public Instance Methods
`(value)
click to toggle source
Return a string literal that will be used directly in an ORDER clause
@param [String] value
@return [Sequel::LiteralString]
@api public
# File lib/rom/sql/dsl.rb, line 54 def `(value) ::Sequel.lit(value) end
call(&block)
click to toggle source
@api private
# 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)
click to toggle source
Returns a result of SQL
EXISTS clause.
@example
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
# File lib/rom/sql/dsl.rb, line 65 def exists(relation) ::ROM::SQL::Attribute[Types::Bool].meta(sql_expr: relation.dataset.exists) end
respond_to_missing?(name, include_private = false)
click to toggle source
@api private
Calls superclass method
# File lib/rom/sql/dsl.rb, line 70 def respond_to_missing?(name, include_private = false) super || schema.key?(name) end
Private Instance Methods
select_relations(parameters)
click to toggle source
@api private
# File lib/rom/sql/dsl.rb, line 88 def select_relations(parameters) @picked_relations.fetch_or_store(parameters.hash) do keys = parameters.select { |type, _| type == :keyreq } if keys.empty? [relations, nil] else [nil, keys.each_with_object({}) { |(_, k), rs| rs[k] = relations[k] }] end end end
type(identifier)
click to toggle source
@api private
# File lib/rom/sql/dsl.rb, line 77 def type(identifier) type_name = Inflector.classify(identifier) types.const_get(type_name) if types.const_defined?(type_name) end
types()
click to toggle source
@api private
# File lib/rom/sql/dsl.rb, line 83 def types ::ROM::SQL::Types end