class GroongaSchema::Table
Attributes
columns[RW]
default_tokenizer[RW]
flags[RW]
key_type[RW]
name[R]
normalizer[RW]
reference_key_type[W]
token_filters[RW]
type[RW]
value_type[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/groonga-schema/table.rb, line 31 def initialize(name) @name = name @type = :no_key @flags = [] @key_type = nil @value_type = nil @default_tokenizer = nil @normalizer = nil @token_filters = [] @reference_key_type = false @columns = [] @related_tables = [] @related_columns = [] end
Public Instance Methods
==(other)
click to toggle source
# File lib/groonga-schema/table.rb, line 55 def ==(other) return false unless other.is_a?(self.class) @name == other.name and @type == other.type and @flags.sort == other.flags.sort and @key_type == other.key_type and @value_type == other.value_type and @default_tokenizer == other.default_tokenizer and @normalizer == other.normalizer and @token_filters == other.token_filters end
apply_command(command)
click to toggle source
# File lib/groonga-schema/table.rb, line 50 def apply_command(command) applier = CommandApplier.new(self, command) applier.apply end
reference_key_type?()
click to toggle source
# File lib/groonga-schema/table.rb, line 46 def reference_key_type? @reference_key_type end
to_create_groonga_command()
click to toggle source
# File lib/groonga-schema/table.rb, line 68 def to_create_groonga_command table_create_command(@name) end
to_migrate_finish_groonga_commands()
click to toggle source
# File lib/groonga-schema/table.rb, line 96 def to_migrate_finish_groonga_commands commands = [] sorted_columns = @columns.sort_by(&:name) sorted_columns.each do |column| next unless column.type == :index commands << column.to_create_groonga_command end commands << table_remove_command(old_name) commands end
to_migrate_start_groonga_commands()
click to toggle source
# File lib/groonga-schema/table.rb, line 76 def to_migrate_start_groonga_commands commands = [] commands << table_create_command(new_name) if @columns.empty? commands << table_copy_command(@name, new_name) else sorted_columns = @columns.sort_by(&:name) sorted_columns.each do |column| next if column.type == :index new_column = Column.new(new_name, column.name) new_column.apply_column(column) commands << new_column.to_create_groonga_command commands << column.to_copy_groonga_command(new_name, column.name) end end commands << table_rename_command(@name, old_name) commands << table_rename_command(new_name, @name) commands end
to_remove_groonga_command()
click to toggle source
# File lib/groonga-schema/table.rb, line 72 def to_remove_groonga_command table_remove_command(@name) end
Private Instance Methods
new_name()
click to toggle source
# File lib/groonga-schema/table.rb, line 112 def new_name "#{@name}_new" end
old_name()
click to toggle source
# File lib/groonga-schema/table.rb, line 108 def old_name "#{@name}_old" end
table_copy_command(from_name, to_name)
click to toggle source
# File lib/groonga-schema/table.rb, line 139 def table_copy_command(from_name, to_name) arguments = { "from_name" => from_name, "to_name" => to_name, } Groonga::Command::TableCopy.new(arguments) end
table_create_command(name)
click to toggle source
# File lib/groonga-schema/table.rb, line 116 def table_create_command(name) flags_value = [type_flag, *flags].join("|") token_filters_value = @token_filters.join("|") token_filters_value = nil if token_filters_value.empty? arguments = { "name" => name, "flags" => flags_value, "key_type" => @key_type, "value_type" => @value_type, "default_tokenizer" => @default_tokenizer, "normalizer" => @normalizer, "token_filters" => token_filters_value, } Groonga::Command::TableCreate.new(arguments) end
table_remove_command(name)
click to toggle source
# File lib/groonga-schema/table.rb, line 132 def table_remove_command(name) arguments = { "name" => name, } Groonga::Command::TableRemove.new(arguments) end
table_rename_command(name, new_name)
click to toggle source
# File lib/groonga-schema/table.rb, line 147 def table_rename_command(name, new_name) arguments = { "name" => name, "new_name" => new_name, } Groonga::Command::TableRename.new(arguments) end
type_flag()
click to toggle source
# File lib/groonga-schema/table.rb, line 155 def type_flag case @type when :no_key "TABLE_NO_KEY" when :hash_key "TABLE_HASH_KEY" when :pat_key "TABLE_PAT_KEY" when :dat_key "TABLE_DAT_KEY" else "TABLE_HASH_KEY" end end