[Groonga-commit] droonga/droonga-engine at 3ed4b9d [master] groonga: Implement table_list command

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Apr 24 11:59:57 JST 2014


YUKI Hiroshi	2014-04-24 11:59:57 +0900 (Thu, 24 Apr 2014)

  New Revision: 3ed4b9d90e88e474a5fddc6f7d51fba084f60df8
  https://github.com/droonga/droonga-engine/commit/3ed4b9d90e88e474a5fddc6f7d51fba084f60df8

  Message:
    groonga: Implement table_list command

  Added files:
    lib/droonga/plugins/groonga/table_list.rb
  Modified files:
    lib/droonga/plugins/groonga.rb
    lib/droonga/plugins/groonga/generic_response.rb

  Modified: lib/droonga/plugins/groonga.rb (+1 -0)
===================================================================
--- lib/droonga/plugins/groonga.rb    2014-04-24 11:48:26 +0900 (7373aab)
+++ lib/droonga/plugins/groonga.rb    2014-04-24 11:59:57 +0900 (fd18c1d)
@@ -28,6 +28,7 @@ require "droonga/plugins/groonga/generic_response"
 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"

  Modified: lib/droonga/plugins/groonga/generic_response.rb (+1 -0)
===================================================================
--- lib/droonga/plugins/groonga/generic_response.rb    2014-04-24 11:48:26 +0900 (cbb9397)
+++ lib/droonga/plugins/groonga/generic_response.rb    2014-04-24 11:59:57 +0900 (adc6fb1)
@@ -23,6 +23,7 @@ module Droonga
           groonga_commands = [
             "table_create",
             "table_remove",
+            "table_list",
             "column_create",
             "column_remove",
             "column_rename",

  Added: lib/droonga/plugins/groonga/table_list.rb (+124 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/plugins/groonga/table_list.rb    2014-04-24 11:59:57 +0900 (281eb58)
@@ -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
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index