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/associations_dsl.rb,
lib/rom/sql/extensions/mysql/inferrer.rb,
lib/rom/sql/extensions/sqlite/inferrer.rb,
lib/rom/sql/extensions/postgres/inferrer.rb

Defined Under Namespace

Classes: AssociationsDSL, DSL, Inferrer, MysqlInferrer, PostgresInferrer, SqliteInferrer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

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 Schema.



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

def initialize(*)
  super
  initialize_primary_key_names
end

Instance Attribute Details

#primary_key_nameObject (readonly)

Returns the value of attribute primary_key_name.



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

def primary_key_name
  @primary_key_name
end

#primary_key_namesObject (readonly)

Returns the value of attribute primary_key_names.



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

def primary_key_names
  @primary_key_names
end

Instance Method Details

#call(relation) ⇒ Relation

Create a new relation based on the schema definition

Parameters:

  • relation (Relation)

    The source relation

Returns:



94
95
96
# File 'lib/rom/sql/schema.rb', line 94

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

#canonicalSchema

Return a new schema with attributes restored to canonical form

Returns:



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

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

#finalize!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.



99
100
101
102
103
# File 'lib/rom/sql/schema.rb', line 99

def finalize!(*)
  super do
    initialize_primary_key_names
  end
end

#group(&block) ⇒ Object



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

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

#initialize_primary_key_namesObject

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.



106
107
108
109
110
111
# File 'lib/rom/sql/schema.rb', line 106

def initialize_primary_key_names
  if primary_key.size > 0
    @primary_key_name = primary_key[0].meta[:name]
    @primary_key_names = primary_key.map { |type| type.meta[:name] }
  end
end

#join(other) ⇒ Object



78
79
80
# File 'lib/rom/sql/schema.rb', line 78

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

#joinedObject



83
84
85
# File 'lib/rom/sql/schema.rb', line 83

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

#order(&block) ⇒ Object



31
32
33
# File 'lib/rom/sql/schema.rb', line 31

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

#project(*names, &block) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/rom/sql/schema.rb', line 59

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

#project_fk(mapping) ⇒ 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.



73
74
75
# File 'lib/rom/sql/schema.rb', line 73

def project_fk(mapping)
  new(rename(mapping).map(&:foreign_key))
end

#project_pkObject

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.



68
69
70
# File 'lib/rom/sql/schema.rb', line 68

def project_pk
  project(*primary_key_names)
end

#qualifiedSchema

Return a new schema with attributes marked as qualified

Returns:



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

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

#restriction(&block) ⇒ Object



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

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