Navigation Menu

Skip to content

Commit

Permalink
groonga: Implement table_list command
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 24, 2014
1 parent 3f731d8 commit 3ed4b9d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/droonga/plugins/groonga.rb
Expand Up @@ -28,6 +28,7 @@ module Groonga
require "droonga/plugins/groonga/select"
require "droonga/plugins/groonga/table_create"
require "droonga/plugins/groonga/table_remove"
require "droonga/plugins/groonga/table_list"
require "droonga/plugins/groonga/column_create"
require "droonga/plugins/groonga/column_remove"
require "droonga/plugins/groonga/column_rename"
Expand Down
1 change: 1 addition & 0 deletions lib/droonga/plugins/groonga/generic_response.rb
Expand Up @@ -23,6 +23,7 @@ class Adapter < Droonga::Adapter
groonga_commands = [
"table_create",
"table_remove",
"table_list",
"column_create",
"column_remove",
"column_rename",
Expand Down
124 changes: 124 additions & 0 deletions lib/droonga/plugins/groonga/table_list.rb
@@ -0,0 +1,124 @@
# Copyright (C) 2014 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "groonga/command/table-list"

require "droonga/plugin"
require "droonga/plugins/groonga/generic_command"

module Droonga
module Plugins
module Groonga
module TableList
HEADER = [
["id", "UInt32"],
["name","ShortText"],
["path","ShortText"],
["flags","ShortText"],
["domain", "ShortText"],
["range", "ShortText"],
["default_tokenizer","ShortText"],
["normalier","ShortText"],
].freeze

class Command < GenericCommand
def process_request(request)
command_class = ::Groonga::Command.find("table_list")
@command = command_class.new("table_list", request)

tables = list_tables(table_name)
[HEADER, *tables]
end

private
def list_tables(table_name)
@context.database.tables.collect do |table|
format_table(table)
end
end

def format_table(table)
[
table.id,
table.local_name,
table.path,
table_flags(table),
domain_name(table),
range_name(table),
default_tokenizer_name(table),
normalizer_name(table),
]
end

def table_flags(table)
flags = []
case table
when ::Groonga::Array
flags << "TABLE_NO_KEY"
when ::Groonga::Hash
flags << "TABLE_HASH_KEY"
when ::Groonga::PatriciaTrie
flags << "TABLE_PAT_KEY"
when ::Groonga::DoubleArrayTrie
flags << "TABLE_DAT_KEY"
end
if table.domain
if table.is_a?(::Groonga::PatriciaTrie) and
table.register_key_with_sis?
flags << "KEY_WITH_SIS"
end
end
flags << "PERSISTENT"
flags.join("|")
end

def domain_name(table)
return nil unless table.domain
table.domain.name
end

def range_name(table)
return nil unless table.range
table.range.name
end

def default_tokenizer_name(table)
return nil unless table.default_tokenizer
table.default_tokenizer.name
end

def normalizer_name(table)
return nil unless table.domain
return nil unless table.normalizer
table.normalizer.name
end
end

class Handler < Droonga::Handler
def handle(message)
command = Command.new(@context)
command.execute(message.request)
end
end

Groonga.define_single_step do |step|
step.name = "table_list"
step.handler = Handler
step.collector = Collectors::Or
end
end
end
end
end

0 comments on commit 3ed4b9d

Please sign in to comment.