Class: Sequel::Postgres::PropertyGraph::Generator::AlterElement
- Inherits:
-
Sequel::Postgres::PropertyGraph::Generator
- Object
- Sequel::Postgres::PropertyGraph::Generator
- Sequel::Postgres::PropertyGraph::Generator::AlterElement
- Defined in:
- lib/sequel/adapters/shared/postgres.rb
Overview
AlterElement is used to evaluate the block passed to Alter#alter_vertex_table and Alter#alter_edge_table.
Constant Summary
Constants inherited from Sequel::Postgres::PropertyGraph::Generator
Instance Method Summary collapse
-
#add_label(name, properties = :all) ⇒ Object
Add a label (and optional properties) to the vertex/edge table.
-
#add_properties(label, properties) ⇒ Object
Add properties to an existing label on the vertex/edge table.
- #data ⇒ Object
-
#drop_label(name, opts = OPTS) ⇒ Object
Remove a label from the vertex/edge table.
-
#drop_properties(label, properties, opts = OPTS) ⇒ Object
Remove properties from an existing label on the vertex/edge table.
-
#initialize(kind, name, &block) ⇒ AlterElement
constructor
kindis:vertexor:edge.
Methods inherited from Sequel::Postgres::PropertyGraph::Generator
Constructor Details
#initialize(kind, name, &block) ⇒ AlterElement
kind is :vertex or :edge. name is the alias of the
vertex or edge table to alter.
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/sequel/adapters/shared/postgres.rb', line 456 def initialize(kind, name, &block) @kind = kind @name = name @labels = [] @operations = [] instance_exec(&block) # All labels added via #add_label are combined into a single # ADD LABEL operation, as PostgreSQL supports adding multiple # labels in a single ALTER ... ADD LABEL statement. unless @labels.empty? @operations << {:op=>:add_label, :kind=>kind, :name=>name, :labels=>@labels.freeze} end @operations.each(&:freeze) @operations.freeze freeze end |
Instance Method Details
#add_label(name, properties = :all) ⇒ Object
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
485 486 487 488 |
# File 'lib/sequel/adapters/shared/postgres.rb', line 485 def add_label(name, properties=:all) @labels << [name, properties].freeze nil end |
#add_properties(label, properties) ⇒ Object
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)
507 508 509 510 |
# File 'lib/sequel/adapters/shared/postgres.rb', line 507 def add_properties(label, properties) @operations << {:op=>:add_properties, :kind=>@kind, :name=>@name, :label=>label, :properties=>Array(properties)} nil end |
#data ⇒ Object
475 476 477 |
# File 'lib/sequel/adapters/shared/postgres.rb', line 475 def data @operations end |
#drop_label(name, opts = OPTS) ⇒ Object
Remove a label from the vertex/edge table. Options: :cascade :: Use CASCADE to drop dependent objects.
drop_label(:l)
# DROP LABEL l
495 496 497 498 |
# File 'lib/sequel/adapters/shared/postgres.rb', line 495 def drop_label(name, opts=OPTS) @operations << {:op=>:drop_label, :kind=>@kind, :name=>@name, :label=>name, :cascade=>opts[:cascade]} nil end |
#drop_properties(label, properties, opts = OPTS) ⇒ Object
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)
518 519 520 521 |
# File 'lib/sequel/adapters/shared/postgres.rb', line 518 def drop_properties(label, properties, opts=OPTS) @operations << {:op=>:drop_properties, :kind=>@kind, :name=>@name, :label=>label, :properties=>Array(properties), :cascade=>opts[:cascade]} nil end |