Class: ROM::SQL::Schema
- Inherits:
-
ROM::Schema
- Object
- ROM::Schema
- ROM::SQL::Schema
- 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
-
#primary_key_name ⇒ Object
readonly
Returns the value of attribute primary_key_name.
-
#primary_key_names ⇒ Object
readonly
Returns the value of attribute primary_key_names.
Instance Method Summary collapse
-
#call(relation) ⇒ Relation
Create a new relation based on the schema definition.
-
#canonical ⇒ Schema
Return a new schema with attributes restored to canonical form.
- #finalize! ⇒ Object private
- #group(&block) ⇒ Object
-
#initialize ⇒ Schema
constructor
private
A new instance of Schema.
- #initialize_primary_key_names ⇒ Object private
- #join(other) ⇒ Object
- #joined ⇒ Object
- #order(&block) ⇒ Object
- #project(*names, &block) ⇒ Object
- #project_fk(mapping) ⇒ Object private
- #project_pk ⇒ Object private
-
#qualified ⇒ Schema
Return a new schema with attributes marked as qualified.
- #restriction(&block) ⇒ Object
Constructor Details
#initialize ⇒ Schema
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_name ⇒ Object (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_names ⇒ Object (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
94 95 96 |
# File 'lib/rom/sql/schema.rb', line 94 def call(relation) relation.new(relation.dataset.select(*self), schema: self) end |
#canonical ⇒ Schema
Return a new schema with attributes restored to canonical form
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_names ⇒ 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.
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].[:name] @primary_key_names = primary_key.map { |type| type.[:name] } end end |
#join(other) ⇒ Object
78 79 80 |
# File 'lib/rom/sql/schema.rb', line 78 def join(other) merge(other.joined) end |
#joined ⇒ Object
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_pk ⇒ 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.
68 69 70 |
# File 'lib/rom/sql/schema.rb', line 68 def project_pk project(*primary_key_names) end |
#qualified ⇒ Schema
Return a new schema with attributes marked as qualified
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 |