AlterElement is used to evaluate the block passed to Alter#alter_vertex_table and Alter#alter_edge_table.
Public Class methods
kind is :vertex or :edge. name is the alias of the vertex or edge table to alter.
# 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 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
# 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 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)
# 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
# File lib/sequel/adapters/shared/postgres.rb 475 def data 476 @operations 477 end
Remove a label from the vertex/edge table. Options:
| :cascade |
Use CASCADE to drop dependent objects. |
drop_label(:l) # DROP LABEL l
# 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
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)
# 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