[Groonga-commit] ranguba/groonga-client-model at 1095f83 [master] Check table existence

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Mon Dec 5 17:06:35 JST 2016


Kouhei Sutou	2016-12-05 17:06:35 +0900 (Mon, 05 Dec 2016)

  New Revision: 1095f8363a69fb01033a591e47cbb47b6b17d32f
  https://github.com/ranguba/groonga-client-model/commit/1095f8363a69fb01033a591e47cbb47b6b17d32f

  Message:
    Check table existence

  Modified files:
    lib/groonga_client_model/record.rb
    lib/groonga_client_model/schema.rb

  Modified: lib/groonga_client_model/record.rb (+4 -2)
===================================================================
--- lib/groonga_client_model/record.rb    2016-12-05 17:06:17 +0900 (ffdbabe)
+++ lib/groonga_client_model/record.rb    2016-12-05 17:06:35 +0900 (c680ff3)
@@ -47,7 +47,8 @@ module GroongaClientModel
 
       def all
         Client.open do |client|
-          response = client.select(table: table_name,
+          table = schema.tables[table_name]
+          response = client.select(table: table.name,
                                    limit: -1)
           response.records.collect do |attributes|
             record = new(attributes)
@@ -59,7 +60,8 @@ module GroongaClientModel
 
       def find(id)
         Client.open do |client|
-          response = client.select(table: table_name,
+          table = schema.tables[table_name]
+          response = client.select(table: table.name,
                                    filter: "_id == #{id}",
                                    limit: 1)
           attributes = response.records.first

  Modified: lib/groonga_client_model/schema.rb (+10 -1)
===================================================================
--- lib/groonga_client_model/schema.rb    2016-12-05 17:06:17 +0900 (53441dc)
+++ lib/groonga_client_model/schema.rb    2016-12-05 17:06:35 +0900 (a024111)
@@ -38,10 +38,15 @@ module GroongaClientModel
       end
 
       def [](name)
+        name = name.to_s if name.is_a?(Symbol)
         raw_table = @raw[name]
-        raise Error, "table doesn't exist: <#{name}>" if raw_table.nil?
+        raise Error, "table doesn't exist: <#{name.inspect}>" if raw_table.nil?
         Table.new(raw_table)
       end
+
+      def exist?(name)
+        @raw.key?(name)
+      end
     end
 
     class Table
@@ -49,6 +54,10 @@ module GroongaClientModel
         @raw = raw
       end
 
+      def name
+        @raw.name
+      end
+
       def columns
         raw_columns =****@raw*****("_id" => {"name" => "_id"})
         if****@raw*****_type
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る