Class: Sequel::Postgres::PropertyGraph::Generator::Element

Inherits:
Sequel::Postgres::PropertyGraph::Generator show all
Defined in:
lib/sequel/adapters/shared/postgres.rb

Overview

Base class for Vertex and Edge.

Direct Known Subclasses

Edge

Defined Under Namespace

Classes: Data

Constant Summary

Constants inherited from Sequel::Postgres::PropertyGraph::Generator

Vertex

Instance Method Summary collapse

Methods inherited from Sequel::Postgres::PropertyGraph::Generator

new

Constructor Details

#initialize(name, opts = OPTS, &block) ⇒ Element

name specifies the name of the vertex or edge. It can be an SQL::AliasedExpression to use an alias. Options: :properties :: Specifies fixed properties for the vertex or edge. If this is given, you cannot use the label method inside the block.



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/sequel/adapters/shared/postgres.rb', line 284

def initialize(name, opts=OPTS, &block)
  @name = name
  @labels = []
  if opts.key?(:properties)
    @labels << [nil, opts[:properties]].freeze
    @labels.freeze
  end
  instance_exec(&block) if block
  @labels.freeze
  freeze
end

Instance Method Details

#dataObject



296
297
298
# File 'lib/sequel/adapters/shared/postgres.rb', line 296

def data
  Data.new(@name, @key, @labels).freeze
end

#key(columns) ⇒ Object

Set the column(s) to use for the KEY clause, which are the columns that uniquely identify rows in the table:

key(:id)
# KEY (id)

key([:id1, :id2])
# KEY (id1, id2)


308
309
310
# File 'lib/sequel/adapters/shared/postgres.rb', line 308

def key(columns)
  @key = Array(columns)
end

#label(name, properties = :all) ⇒ Object

Add a label and properties for the label for this vertex/edge.
A vertex or edge can have multiple labels with separate properties, if it wasn't created with fixed properties. The name argument specifies the label name. The properties argument specifies the properties: nil, :all :: PROPERTIES ALL COLUMNS false, :none, [] :: NO PROPERTIES

Array

Array of specific properties. Each element should be a Symbol, SQL::Identifier, or SQL::AliasedExpression.

label(:label_name)

LABEL label_name PROPERTIES ALL COLUMNS

label(:label_name, [])
# LABEL label_name NO PROPERTIES

label(:label_name, [:c, Sequel[:b].as(:d)], Sequel[:e])
# LABEL label_name PROPERTIES (c, b AS d, e)


330
331
332
333
334
335
336
# File 'lib/sequel/adapters/shared/postgres.rb', line 330

def label(name, properties=:all)
  if @labels.frozen?
    raise Error, "cannot specify label for property graph vertex or edge with fixed properties"
  end
  @labels << [name, properties].freeze
  nil
end