class Sequel::Postgres::PropertyGraph::Generator::AlterElement

  1. lib/sequel/adapters/shared/postgres.rb
Superclass: self

AlterElement is used to evaluate the block passed to Alter#alter_vertex_table and Alter#alter_edge_table.

Methods

Public Class

  1. new

Public Instance

  1. add_label
  2. add_properties
  3. data
  4. drop_label
  5. drop_properties

Public Class methods

new(kind, name, &block)

kind is :vertex or :edge. name is the alias of the vertex or edge table to alter.

[show source]
    # File lib/sequel/adapters/shared/postgres.rb
456 def initialize(kind, name, &block)
457   @kind = kind
458   @name = name
459   @labels = []
460   @operations = []
461   instance_exec(&block)
462 
463   # All labels added via #add_label are combined into a single
464   # ADD LABEL operation, as PostgreSQL supports adding multiple
465   # labels in a single ALTER ... ADD LABEL statement.
466   unless @labels.empty?
467     @operations << {:op=>:add_label, :kind=>kind, :name=>name, :labels=>@labels.freeze}
468   end
469 
470   @operations.each(&:freeze)
471   @operations.freeze
472   freeze
473 end

Public Instance methods

add_label(name, properties=:all)

Add a label (and optional properties) to the vertex/edge table. Takes the same arguments as Element#label. Can be called multiple times to add multiple labels.

add_label(:l)
# ADD LABEL l PROPERTIES ALL COLUMNS
[show source]
    # File lib/sequel/adapters/shared/postgres.rb
485 def add_label(name, properties=:all)
486   @labels << [name, properties].freeze
487   nil
488 end
add_properties(label, properties)

Add properties to an existing label on the vertex/edge table. properties is an expression, or array of expressions, the same as the explicit array form of the properties argument to Element#label.

add_properties(:l, [:c1, Sequel[:c2].as(:c3)])
# ALTER LABEL l ADD PROPERTIES (c1, c2 AS c3)
[show source]
    # File lib/sequel/adapters/shared/postgres.rb
507 def add_properties(label, properties)
508   @operations << {:op=>:add_properties, :kind=>@kind, :name=>@name, :label=>label, :properties=>Array(properties)}
509   nil
510 end
data()
[show source]
    # File lib/sequel/adapters/shared/postgres.rb
475 def data
476   @operations
477 end
drop_label(name, opts=OPTS)

Remove a label from the vertex/edge table. Options:

:cascade

Use CASCADE to drop dependent objects.

drop_label(:l)
# DROP LABEL l
[show source]
    # File lib/sequel/adapters/shared/postgres.rb
495 def drop_label(name, opts=OPTS)
496   @operations << {:op=>:drop_label, :kind=>@kind, :name=>@name, :label=>name, :cascade=>opts[:cascade]}
497   nil
498 end
drop_properties(label, properties, opts=OPTS)

Remove properties from an existing label on the vertex/edge table. properties is a column name, or array of column names. Options:

:cascade

Use CASCADE to drop dependent objects.

drop_properties(:l, [:c1])
# ALTER LABEL l DROP PROPERTIES (c1)
[show source]
    # File lib/sequel/adapters/shared/postgres.rb
518 def drop_properties(label, properties, opts=OPTS)
519   @operations << {:op=>:drop_properties, :kind=>@kind, :name=>@name, :label=>label, :properties=>Array(properties), :cascade=>opts[:cascade]}
520   nil
521 end