Class: ROM::SQL::Schema

Inherits:
ROM::Schema
  • Object
show all
Defined in:
lib/rom/sql/schema.rb,
lib/rom/sql/schema/dsl.rb,
lib/rom/sql/schema/inferrer.rb,
lib/rom/sql/schema/index_dsl.rb,
lib/rom/sql/schema/type_builder.rb,
lib/rom/sql/schema/attributes_inferrer.rb

Overview

Specialized schema for SQL databases

Defined Under Namespace

Classes: DSL, IndexDSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#foreign_keysArray<ForeignKey> (readonly)

Returns Array with foreign keys.

Returns:

  • (Array<ForeignKey>)

    Array with foreign keys



26
# File 'lib/rom/sql/schema.rb', line 26

option :foreign_keys, default: -> { EMPTY_SET }

#indexesArray<Index> (readonly)

Returns Array with schema indexes.

Returns:

  • (Array<Index>)

    Array with schema indexes



22
# File 'lib/rom/sql/schema.rb', line 22

option :indexes, default: -> { EMPTY_SET }

Instance Method Details

#call(relation) ⇒ Relation

Create a new relation based on the schema definition

Parameters:

  • relation (Relation)

    The source relation

Returns:



131
132
133
# File 'lib/rom/sql/schema.rb', line 131

def call(relation)
  relation.new(relation.dataset.select(*self), schema: self)
end

#emptySchema

Return an empty schema

Returns:



140
141
142
# File 'lib/rom/sql/schema.rb', line 140

def empty
  new(EMPTY_ARRAY)
end

#group(&block) ⇒ Mixed

Open Group DSL for setting GROUP BY clause in queries

Returns:

  • (Mixed)

    Result of the block call

See Also:



57
58
59
# File 'lib/rom/sql/schema.rb', line 57

def group(&block)
  GroupDSL.new(self).call(&block)
end

#join(other) ⇒ Schema

Join with another schema

Parameters:

  • other (Schema)

    The other schema to join with

Returns:



111
112
113
# File 'lib/rom/sql/schema.rb', line 111

def join(other)
  merge(other.joined)
end

#joinedSchema

Return a new schema with all attributes marked as joined

Returns:



120
121
122
# File 'lib/rom/sql/schema.rb', line 120

def joined
  new(map(&:joined))
end

#order(&block) ⇒ Mixed

Open Order DSL for setting ORDER clause in queries

Returns:

  • (Mixed)

    Result of the block call

See Also:



46
47
48
# File 'lib/rom/sql/schema.rb', line 46

def order(&block)
  OrderDSL.new(self).call(&block)
end

#project(*names, &block) ⇒ Schema

Project a schema

Returns:

  • (Schema)

    A new schema with projected attributes

See Also:



78
79
80
81
82
83
84
# File 'lib/rom/sql/schema.rb', line 78

def project(*names, &block)
  if block
    super(*(names + ProjectionDSL.new(self).(&block)))
  else
    super
  end
end

#qualified(table_alias = nil) ⇒ Schema

Return a new schema with attributes marked as qualified

Returns:



66
67
68
# File 'lib/rom/sql/schema.rb', line 66

def qualified(table_alias = nil)
  new(map { |attr| attr.qualified(table_alias) })
end

#restriction(&block) ⇒ Mixed

Open restriction DSL for defining query conditions using schema attributes

Returns:

  • (Mixed)

    Result of the block call

See Also:



35
36
37
# File 'lib/rom/sql/schema.rb', line 35

def restriction(&block)
  RestrictionDSL.new(self).call(&block)
end