Represents a GRAPH_TABLE expression, used to query a property graph via graph pattern matching. This is used in place of a table name expression or dataset in a SELECT query. These are created by calling graph_table on the related Database object.
Table uses a method chaining design, similar to Dataset, where methods return modified frozen copies of the object.
Methods
Public Class
Public Instance
Included modules
- SQL::AliasMethods
Attributes
| columns | [R] |
A frozen array of the columns used in the COLUMNS clause (aliased as |
| columns_used | [R] |
A frozen array of the columns used in the COLUMNS clause (aliased as |
| elements | [R] |
A frozen array of Element instances, representing the vertices and edges in the graph pattern. |
| name | [R] |
The name of the property graph the table is querying. |
Public Class methods
Create a new Table with the given graph_name, with initial_vertex_label and initial_vertex_opts being used to create the initial vertex. See Table#link for which options are supported for the initial vertex.
# File lib/sequel/adapters/shared/postgres.rb 682 def self.create(graph_name, initial_vertex_label, initial_vertex_opts) 683 vertex = Element.create(:vertex, "", initial_vertex_label, initial_vertex_opts) 684 new(graph_name, [vertex].freeze, [].freeze) 685 end
# File lib/sequel/adapters/shared/postgres.rb 687 def initialize(name, elements, columns) 688 @name = name 689 @elements = elements 690 @columns = columns 691 freeze 692 end
Public Instance methods
Return a modified copy that adds the given columns to the existing list of columns for the graph table.
# File lib/sequel/adapters/shared/postgres.rb 745 def add_columns(*cols) 746 columns(*@columns, *cols) 747 end
Similar to link, but uses a directed link from the new element to the previous element (<- in the graph pattern). Accepts same arguments and options as link.
DB.graph_table(:gn, :v).from(:e) # GRAPH_TABLE (gn MATCH (IS v)<-[IS e])
# File lib/sequel/adapters/shared/postgres.rb 730 def from(label, opts=OPTS) 731 append_element('<-', label, opts) 732 end
Return a modified copy with an element added using a bidirectional link (- in the graph pattern). label specifies the label restriction for the element. This can be nil for no label restriction, or an array or set to restrict to the given labels.
Options supported:
:var |
Specifies a graph pattern variable name for the element, usable in the WHERE or COLUMNS clauses. |
:vertex |
Specifies that the element being linked to is a vertex. This allows for direct vertex<->vertex linking, instead of the default vertex<->edge<->vertex linking. |
:where |
An expression to use for the WHERE clause for the element. |
DB.graph_table(:gn, :v).link(:e) # GRAPH_TABLE (gn MATCH (IS v)-[IS e])
# File lib/sequel/adapters/shared/postgres.rb 710 def link(label, opts=OPTS) 711 append_element('-', label, opts) 712 end
Append the SQL for the GRAPH_TABLE expression to the given SQL string. Requires graph table have at least one column set.
# File lib/sequel/adapters/shared/postgres.rb 751 def sql_literal_append(ds, sql) 752 if @columns.empty? 753 raise Error, "cannot use graph_table in a query if it does not return any columns" 754 end 755 if @elements.last.type == :edge 756 raise Error, "cannot use graph_table in a query if the last element is an edge" 757 end 758 759 sql << "GRAPH_TABLE (" 760 ds.literal_append(sql, @name) 761 sql << " MATCH " 762 763 @elements.each do |element| 764 marker = element.marker 765 var = element.var 766 label = element.label 767 where = element.where 768 vertex = element.type == :vertex 769 770 sql << marker 771 sql << (vertex ? '(' : '[') 772 773 ds.literal_append(sql, var) if var 774 if label 775 sql << (var ? " IS " : "IS ") 776 if label.is_a?(Array) 777 label_sep = "" 778 label.each do |l| 779 sql << label_sep 780 label_sep = "|" if label_sep.empty? 781 ds.literal_append(sql, l) 782 end 783 else 784 ds.literal_append(sql, label) 785 end 786 end 787 788 if where 789 sql << ((var || label) ? " WHERE " : "WHERE ") 790 ds.literal_append(sql, where) 791 end 792 793 sql << (vertex ? ')' : ']') 794 end 795 796 sql << " COLUMNS " 797 ds.literal_append(sql, @columns) 798 sql << ")" 799 end
Similar to link, but uses a directed link from the previous element to the new element (-> in the graph pattern). Accepts same arguments and options as link.
DB.graph_table(:gn, :v).to(:e) # GRAPH_TABLE (gn MATCH (IS v)->[IS e])
# File lib/sequel/adapters/shared/postgres.rb 720 def to(label, opts=OPTS) 721 append_element('->', label, opts) 722 end