class ROM::SQL::Schema
Specialized schema for SQL
databases
@api public
Public Instance Methods
Create a new relation based on the schema definition
@param [Relation] relation The source relation
@return [Relation]
@api public
# File lib/rom/sql/schema.rb, line 143 def call(relation) relation.new(relation.dataset.select(*self.qualified_projection), schema: self) end
Return an empty schema
@return [Schema]
@api public
# File lib/rom/sql/schema.rb, line 152 def empty new(EMPTY_ARRAY) end
Finalize associations
@api private
# File lib/rom/sql/schema.rb, line 168 def finalize_associations!(relations:) super do associations.map do |definition| SQL::Associations.const_get(definition.type).new(definition, relations) end end end
Finalize all attributes by qualifying them and initializing primary key names
@api private
# File lib/rom/sql/schema.rb, line 159 def finalize_attributes!(**options) super do @attributes = map(&:qualified) end end
Open Group DSL
for setting GROUP BY clause in queries
@see Relation#group
@return [Mixed] Result of the block call
@api public
# File lib/rom/sql/schema.rb, line 57 def group(&block) GroupDSL.new(self).call(&block) end
Join with another schema
@param [Schema] other The other schema to join with
@return [Schema]
@api public
# File lib/rom/sql/schema.rb, line 123 def join(other) merge(other.joined) end
Return a new schema with all attributes marked as joined
@return [Schema]
@api public
# File lib/rom/sql/schema.rb, line 132 def joined new(map(&:joined)) end
Open Order DSL
for setting ORDER clause in queries
@see Relation#order
@return [Mixed] Result of the block call
@api public
# File lib/rom/sql/schema.rb, line 46 def order(&block) OrderDSL.new(self).call(&block) end
Project a schema
@see ROM::Schema#project @see Relation#select
@return [Schema] A new schema with projected attributes
@api public
# File lib/rom/sql/schema.rb, line 90 def project(*names, &block) if block super(*(names + ProjectionDSL.new(self).(&block))) else super end end
Project schema so that it only contains renamed foreign key
@return [Schema]
@api private
# File lib/rom/sql/schema.rb, line 112 def project_fk(mapping) new(rename(mapping).map(&:foreign_key)) end
Project schema so that it only contains primary key
@return [Schema]
@api private
# File lib/rom/sql/schema.rb, line 103 def project_pk project(*primary_key_names) end
Return a new schema with attributes marked as qualified
@return [Schema]
@api public
# File lib/rom/sql/schema.rb, line 66 def qualified(table_alias = nil) new(map { |attr| attr.qualified(table_alias) }) end
Return a new schema with attributes that are aliased and marked as qualified
Intended to be used when passing attributes to ‘dataset#select`
@return [Schema]
@api public
# File lib/rom/sql/schema.rb, line 78 def qualified_projection(table_alias = nil) new(map { |attr| attr.qualified_projection(table_alias) }) end
Open restriction DSL
for defining query conditions using schema attributes
@see Relation#where
@return [Mixed] Result of the block call
@api public
# File lib/rom/sql/schema.rb, line 35 def restriction(&block) RestrictionDSL.new(self).call(&block) end