Module: ActiveRecordExtended::Ltree
- Defined in:
- lib/active_record_extended/ltree_query_methods.rb
Overview
Arel helpers for ltree functions - can be used in complex queries
Class Method Summary collapse
-
.index(column, search) ⇒ Object
index(ltree, ltree) - Returns position of first occurrence of second argument.
-
.lca(*columns) ⇒ Object
lca(ltree, ltree, ...) - Returns longest common ancestor of paths.
-
.ltree2text(column) ⇒ Object
ltree2text(ltree) - Converts ltree to text.
-
.nlevel(column) ⇒ Object
nlevel(ltree) - Returns the number of labels in the path.
-
.subpath(column, offset, len = nil) ⇒ Object
subpath(ltree, offset, len) - Extracts subpath starting at offset for len labels.
-
.text2ltree(value) ⇒ Object
text2ltree(text) - Converts text to ltree.
Class Method Details
.index(column, search) ⇒ Object
index(ltree, ltree) - Returns position of first occurrence of second argument
44 45 46 |
# File 'lib/active_record_extended/ltree_query_methods.rb', line 44 def index(column, search) Arel::Nodes::NamedFunction.new('index', [Arel.sql(column.to_s), Arel.sql("'#{search}'")]) end |
.lca(*columns) ⇒ Object
lca(ltree, ltree, ...) - Returns longest common ancestor of paths
38 39 40 41 |
# File 'lib/active_record_extended/ltree_query_methods.rb', line 38 def lca(*columns) args = columns.map { |c| Arel.sql(c.to_s) } Arel::Nodes::NamedFunction.new('lca', args) end |
.ltree2text(column) ⇒ Object
ltree2text(ltree) - Converts ltree to text
54 55 56 |
# File 'lib/active_record_extended/ltree_query_methods.rb', line 54 def ltree2text(column) Arel::Nodes::NamedFunction.new('ltree2text', [Arel.sql(column.to_s)]) end |
.nlevel(column) ⇒ Object
nlevel(ltree) - Returns the number of labels in the path
26 27 28 |
# File 'lib/active_record_extended/ltree_query_methods.rb', line 26 def nlevel(column) Arel::Nodes::NamedFunction.new('nlevel', [Arel.sql(column.to_s)]) end |
.subpath(column, offset, len = nil) ⇒ Object
subpath(ltree, offset, len) - Extracts subpath starting at offset for len labels
31 32 33 34 35 |
# File 'lib/active_record_extended/ltree_query_methods.rb', line 31 def subpath(column, offset, len = nil) args = [Arel.sql(column.to_s), Arel.sql(offset.to_s)] args << Arel.sql(len.to_s) if len Arel::Nodes::NamedFunction.new('subpath', args) end |
.text2ltree(value) ⇒ Object
text2ltree(text) - Converts text to ltree
49 50 51 |
# File 'lib/active_record_extended/ltree_query_methods.rb', line 49 def text2ltree(value) Arel::Nodes::NamedFunction.new('text2ltree', [Arel.sql("'#{value}'")]) end |