Class: ROM::SQL::Relation
- Inherits:
-
Relation
- Object
- Relation
- ROM::SQL::Relation
- Extended by:
- ClassMethods
- Includes:
- Associations, Inspection
- Defined in:
- lib/rom/sql/relation.rb,
lib/rom/sql/relation/inspection.rb,
lib/rom/sql/relation/associations.rb,
lib/rom/sql/relation/class_methods.rb
Overview
Sequel-specific relation extensions
Defined Under Namespace
Modules: Associations, ClassMethods, Inspection
Instance Attribute Summary collapse
-
#header ⇒ Header
readonly
private
Return a header for this relation.
-
#table ⇒ Object
readonly
Name of the table used in FROM clause.
Instance Method Summary collapse
-
#columns ⇒ Array<Symbol>
private
Return raw column names.
-
#count ⇒ Relation
Return relation count.
-
#delete(*args, &block) ⇒ Relation
Delete tuples from the relation.
-
#distinct(*args, &block) ⇒ Relation
Returns a copy of the relation with a SQL DISTINCT clause.
-
#exclude(*args, &block) ⇒ Relation
Restrict a relation to not match criteria.
-
#first ⇒ Relation
Get first tuple from the relation.
-
#group(*args, &block) ⇒ Relation
Group by specific columns.
-
#group_and_count(*args, &block) ⇒ Relation
Group by specific columns and count by group.
-
#initialize(dataset, registry = {}) ⇒ Relation
constructor
private
A new instance of Relation.
-
#inner_join(*args, &block) ⇒ Relation
Join other relation using inner join.
-
#insert(*args, &block) ⇒ Relation
Insert tuple into relation.
-
#invert(*args, &block) ⇒ Relation
Inverts a request.
-
#last ⇒ Relation
Get last tuple from the relation.
-
#left_join(*args, &block) ⇒ Relation
Join other relation using left outer join.
-
#limit(*args, &block) ⇒ Relation
Limit a relation to a specific number of tuples.
-
#map(&block) ⇒ Object
Map tuples from the relation.
-
#offset(*args, &block) ⇒ Relation
Set offset for the relation.
-
#order(*args, &block) ⇒ Relation
Set order for the relation.
-
#prefix(name = Inflector.singularize(table)) ⇒ Relation
Prefix all columns in a relation.
-
#project(*names) ⇒ Relation
Project a relation.
-
#qualified ⇒ Relation
Qualifies all columns in a relation.
-
#qualified_columns ⇒ Relation
Return a list of qualified column names.
-
#rename(options) ⇒ Relation
Rename columns in a relation.
-
#reverse(*args, &block) ⇒ Relation
Reverse the order of the relation.
-
#select(*args, &block) ⇒ Relation
Select specific columns for select clause.
-
#select_append(*args, &block) ⇒ Relation
Append specific columns to select clause.
-
#select_group(*args, &block) ⇒ Relation
Select and group by specific columns.
-
#unique?(criteria) ⇒ Relation
Return if a restricted relation has 0 tuples.
-
#update(*args, &block) ⇒ Relation
Update tuples in the relation.
-
#where(*args, &block) ⇒ Relation
Restrict a relation to match criteria.
Methods included from ClassMethods
finalize, inherited, many_to_many, many_to_one, one_to_many
Methods included from Associations
#association_join, #association_left_join, #graph, #graph_join
Methods included from Inspection
Constructor Details
#initialize(dataset, registry = {}) ⇒ Relation
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 Relation.
28 29 30 31 |
# File 'lib/rom/sql/relation.rb', line 28 def initialize(dataset, registry = {}) super @table = dataset.opts[:from].first end |
Instance Attribute Details
#header ⇒ Header (readonly)
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.
Return a header for this relation
20 21 22 |
# File 'lib/rom/sql/relation.rb', line 20 def header @header end |
#table ⇒ Object (readonly)
Name of the table used in FROM clause
25 26 27 |
# File 'lib/rom/sql/relation.rb', line 25 def table @table end |
Instance Method Details
#columns ⇒ Array<Symbol>
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.
Return raw column names
410 411 412 |
# File 'lib/rom/sql/relation.rb', line 410 def columns dataset.columns end |
#count ⇒ Relation
Return relation count
138 139 140 |
# File 'lib/rom/sql/relation.rb', line 138 def count dataset.count end |
#delete(*args, &block) ⇒ Relation
Delete tuples from the relation
374 375 376 |
# File 'lib/rom/sql/relation.rb', line 374 def delete(*args, &block) dataset.delete(*args, &block) end |
#distinct(*args, &block) ⇒ Relation
Returns a copy of the relation with a SQL DISTINCT clause.
174 175 176 |
# File 'lib/rom/sql/relation.rb', line 174 def distinct(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#exclude(*args, &block) ⇒ Relation
Restrict a relation to not match criteria
198 199 200 |
# File 'lib/rom/sql/relation.rb', line 198 def exclude(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#first ⇒ Relation
Get first tuple from the relation
114 115 116 |
# File 'lib/rom/sql/relation.rb', line 114 def first dataset.first end |
#group(*args, &block) ⇒ Relation
Group by specific columns
307 308 309 |
# File 'lib/rom/sql/relation.rb', line 307 def group(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#group_and_count(*args, &block) ⇒ Relation
Group by specific columns and count by group
320 321 322 |
# File 'lib/rom/sql/relation.rb', line 320 def group_and_count(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#inner_join(*args, &block) ⇒ Relation
Join other relation using inner join
283 284 285 |
# File 'lib/rom/sql/relation.rb', line 283 def inner_join(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#insert(*args, &block) ⇒ Relation
Insert tuple into relation
347 348 349 |
# File 'lib/rom/sql/relation.rb', line 347 def insert(*args, &block) dataset.insert(*args, &block) end |
#invert(*args, &block) ⇒ Relation
Inverts a request
213 214 215 |
# File 'lib/rom/sql/relation.rb', line 213 def invert(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#last ⇒ Relation
Get last tuple from the relation
126 127 128 |
# File 'lib/rom/sql/relation.rb', line 126 def last dataset.last end |
#left_join(*args, &block) ⇒ Relation
Join other relation using left outer join
295 296 297 |
# File 'lib/rom/sql/relation.rb', line 295 def left_join(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#limit(*args, &block) ⇒ Relation
Limit a relation to a specific number of tuples
249 250 251 |
# File 'lib/rom/sql/relation.rb', line 249 def limit(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#map(&block) ⇒ Object
Map tuples from the relation
271 272 273 |
# File 'lib/rom/sql/relation.rb', line 271 def map(&block) to_enum.map(&block) end |
#offset(*args, &block) ⇒ Relation
Set offset for the relation
261 262 263 |
# File 'lib/rom/sql/relation.rb', line 261 def offset(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#order(*args, &block) ⇒ Relation
Set order for the relation
225 226 227 |
# File 'lib/rom/sql/relation.rb', line 225 def order(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#prefix(name = Inflector.singularize(table)) ⇒ Relation
Prefix all columns in a relation
This method is intended to be used internally within a relation object
77 78 79 |
# File 'lib/rom/sql/relation.rb', line 77 def prefix(name = Inflector.singularize(table)) rename(header.prefix(name).to_h) end |
#project(*names) ⇒ Relation
Project a relation
This method is intended to be used internally within a relation object
45 46 47 |
# File 'lib/rom/sql/relation.rb', line 45 def project(*names) select(*header.project(*names)) end |
#qualified ⇒ Relation
Qualifies all columns in a relation
This method is intended to be used internally within a relation object
91 92 93 |
# File 'lib/rom/sql/relation.rb', line 91 def qualified select(*qualified_columns) end |
#qualified_columns ⇒ Relation
Return a list of qualified column names
This method is intended to be used internally within a relation object
102 103 104 |
# File 'lib/rom/sql/relation.rb', line 102 def qualified_columns header.qualified.to_a end |
#rename(options) ⇒ Relation
Rename columns in a relation
This method is intended to be used internally within a relation object
61 62 63 |
# File 'lib/rom/sql/relation.rb', line 61 def rename() select(*header.rename()) end |
#reverse(*args, &block) ⇒ Relation
Reverse the order of the relation
237 238 239 |
# File 'lib/rom/sql/relation.rb', line 237 def reverse(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#select(*args, &block) ⇒ Relation
Select specific columns for select clause
150 151 152 |
# File 'lib/rom/sql/relation.rb', line 150 def select(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#select_append(*args, &block) ⇒ Relation
Append specific columns to select clause
162 163 164 |
# File 'lib/rom/sql/relation.rb', line 162 def select_append(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#select_group(*args, &block) ⇒ Relation
Select and group by specific columns
333 334 335 |
# File 'lib/rom/sql/relation.rb', line 333 def select_group(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#unique?(criteria) ⇒ Relation
Return if a restricted relation has 0 tuples
392 393 394 |
# File 'lib/rom/sql/relation.rb', line 392 def unique?(criteria) where(criteria).count.zero? end |
#update(*args, &block) ⇒ Relation
Update tuples in the relation
360 361 362 |
# File 'lib/rom/sql/relation.rb', line 360 def update(*args, &block) dataset.update(*args, &block) end |
#where(*args, &block) ⇒ Relation
Restrict a relation to match criteria
186 187 188 |
# File 'lib/rom/sql/relation.rb', line 186 def where(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |