Module: ROM::SQL::Relation::Reading
- Included in:
- ROM::SQL::Relation
- Defined in:
- lib/rom/sql/relation/reading.rb
Instance Method Summary collapse
-
#avg(*args) ⇒ Object
Returns a result of SQL AVG clause.
-
#count ⇒ Relation
Return relation count.
-
#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.
-
#inner_join(*args, &block) ⇒ Relation
Join other relation using inner join.
-
#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.
-
#max(*args) ⇒ Object
Returns a result of SQL MAX clause.
-
#min(*args) ⇒ Object
Returns a result of SQL MIN clause.
-
#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.
-
#sum(*args) ⇒ Object
Returns a result of SQL SUM clause.
-
#union(relation, *args, &block) ⇒ Relation
Adds a UNION clause for relation dataset using second relation dataset.
-
#unique?(criteria) ⇒ Relation
Return if a restricted relation has 0 tuples.
-
#where(*args, &block) ⇒ Relation
Restrict a relation to match criteria.
Instance Method Details
#avg(*args) ⇒ Object
Returns a result of SQL AVG clause.
222 223 224 |
# File 'lib/rom/sql/relation/reading.rb', line 222 def avg(*args) dataset.__send__(__method__, *args) end |
#count ⇒ Relation
Return relation count
13 14 15 |
# File 'lib/rom/sql/relation/reading.rb', line 13 def count dataset.count end |
#distinct(*args, &block) ⇒ Relation
Returns a copy of the relation with a SQL DISTINCT clause.
174 175 176 |
# File 'lib/rom/sql/relation/reading.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
246 247 248 |
# File 'lib/rom/sql/relation/reading.rb', line 246 def exclude(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#first ⇒ Relation
Get first tuple from the relation
25 26 27 |
# File 'lib/rom/sql/relation/reading.rb', line 25 def first dataset.first end |
#group(*args, &block) ⇒ Relation
Group by specific columns
345 346 347 |
# File 'lib/rom/sql/relation/reading.rb', line 345 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
358 359 360 |
# File 'lib/rom/sql/relation/reading.rb', line 358 def group_and_count(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#inner_join(*args, &block) ⇒ Relation
Join other relation using inner join
321 322 323 |
# File 'lib/rom/sql/relation/reading.rb', line 321 def inner_join(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#invert(*args, &block) ⇒ Relation
Inverts a request
261 262 263 |
# File 'lib/rom/sql/relation/reading.rb', line 261 def invert(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#last ⇒ Relation
Get last tuple from the relation
37 38 39 |
# File 'lib/rom/sql/relation/reading.rb', line 37 def last dataset.last end |
#left_join(*args, &block) ⇒ Relation
Join other relation using left outer join
333 334 335 |
# File 'lib/rom/sql/relation/reading.rb', line 333 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
297 298 299 |
# File 'lib/rom/sql/relation/reading.rb', line 297 def limit(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#map(&block) ⇒ Object
Map tuples from the relation
106 107 108 |
# File 'lib/rom/sql/relation/reading.rb', line 106 def map(&block) dataset.map(&block) end |
#max(*args) ⇒ Object
Returns a result of SQL MAX clause.
210 211 212 |
# File 'lib/rom/sql/relation/reading.rb', line 210 def max(*args) dataset.__send__(__method__, *args) end |
#min(*args) ⇒ Object
Returns a result of SQL MIN clause.
198 199 200 |
# File 'lib/rom/sql/relation/reading.rb', line 198 def min(*args) dataset.__send__(__method__, *args) end |
#offset(*args, &block) ⇒ Relation
Set offset for the relation
309 310 311 |
# File 'lib/rom/sql/relation/reading.rb', line 309 def offset(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#order(*args, &block) ⇒ Relation
Set order for the relation
273 274 275 |
# File 'lib/rom/sql/relation/reading.rb', line 273 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
53 54 55 |
# File 'lib/rom/sql/relation/reading.rb', line 53 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
122 123 124 |
# File 'lib/rom/sql/relation/reading.rb', line 122 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
67 68 69 |
# File 'lib/rom/sql/relation/reading.rb', line 67 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
78 79 80 |
# File 'lib/rom/sql/relation/reading.rb', line 78 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
138 139 140 |
# File 'lib/rom/sql/relation/reading.rb', line 138 def rename() select(*header.rename()) end |
#reverse(*args, &block) ⇒ Relation
Reverse the order of the relation
285 286 287 |
# File 'lib/rom/sql/relation/reading.rb', line 285 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/reading.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/reading.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
371 372 373 |
# File 'lib/rom/sql/relation/reading.rb', line 371 def select_group(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |
#sum(*args) ⇒ Object
Returns a result of SQL SUM clause.
186 187 188 |
# File 'lib/rom/sql/relation/reading.rb', line 186 def sum(*args) dataset.__send__(__method__, *args) end |
#union(relation, *args, &block) ⇒ Relation
Adds a UNION clause for relation dataset using second relation dataset
386 387 388 |
# File 'lib/rom/sql/relation/reading.rb', line 386 def union(relation, *args, &block) __new__(dataset.__send__(__method__, relation.dataset, *args, &block)) end |
#unique?(criteria) ⇒ Relation
Return if a restricted relation has 0 tuples
96 97 98 |
# File 'lib/rom/sql/relation/reading.rb', line 96 def unique?(criteria) where(criteria).count.zero? end |
#where(*args, &block) ⇒ Relation
Restrict a relation to match criteria
234 235 236 |
# File 'lib/rom/sql/relation/reading.rb', line 234 def where(*args, &block) __new__(dataset.__send__(__method__, *args, &block)) end |