Kouhei Sutou
null+****@clear*****
Tue Dec 6 17:01:55 JST 2016
Kouhei Sutou 2016-12-06 17:01:55 +0900 (Tue, 06 Dec 2016) New Revision: 993ac2d059b8ecaae2bd74420858e8067ffcf330 https://github.com/ranguba/groonga-client-model/commit/993ac2d059b8ecaae2bd74420858e8067ffcf330 Message: Support "load --command_version 3 --output_ids yes" Modified files: groonga-client-model.gemspec lib/groonga_client_model/record.rb test/apps/rails5/Gemfile.lock Modified: groonga-client-model.gemspec (+1 -1) =================================================================== --- groonga-client-model.gemspec 2016-12-06 16:57:08 +0900 (1f435a6) +++ groonga-client-model.gemspec 2016-12-06 17:01:55 +0900 (187f82b) @@ -43,7 +43,7 @@ Gem::Specification.new do |spec| spec.files += Dir.glob("doc/text/*") spec.test_files += Dir.glob("test/**/*") - spec.add_runtime_dependency("groonga-client") + spec.add_runtime_dependency("groonga-client", ">= 0.3.2") spec.add_runtime_dependency("activemodel") spec.add_development_dependency("bundler") Modified: lib/groonga_client_model/record.rb (+21 -15) =================================================================== --- lib/groonga_client_model/record.rb 2016-12-06 16:57:08 +0900 (6f56019) +++ lib/groonga_client_model/record.rb 2016-12-06 17:01:55 +0900 (0df9cdf) @@ -193,31 +193,37 @@ module GroongaClientModel Client.open do |client| table = self.class.schema.tables[self.class.table_name] response = client.load(table: table.name, - values: [attributes]) + values: [attributes], + output_ids: "yes", + command_version: "3") unless response.success? message = "Failed to save: " message << "#{response.error_code}: #{response.error_message}" raise RecordNotSaved.new(message, self) end - if response.body.zero? + if response.n_loaded_records.zero? message = "Failed to save: #{self.inspect}" raise RecordNotSaved.new(message, self) end if @new_record - if****@attri*****?("_key") - select_response = client.select(table: table.name, - # TODO: #{_key} is dangerous - filter: "_key == #{_key}", - limit: 1, - output_columns: "_id") - else - select_response = client.select(table: table.name, - limit: 1, - output_columns: "_id", - # TODO: may return not newly added record - sort_keys: "-_id") + id = response.ids.first + if id.nil? + if****@attri*****?("_key") + select_response = client.select(table: table.name, + # TODO: #{_key} is dangerous + filter: "_key == #{_key}", + limit: 1, + output_columns: "_id") + else + select_response = client.select(table: table.name, + limit: 1, + output_columns: "_id", + # TODO: may return not newly added record + sort_keys: "-_id") + end + id = select_response.records.first["_id"] end - self._id = select_response.records.first["_id"] + self._id = id end @new_record = false true Modified: test/apps/rails5/Gemfile.lock (+2 -2) =================================================================== --- test/apps/rails5/Gemfile.lock 2016-12-06 16:57:08 +0900 (332c422) +++ test/apps/rails5/Gemfile.lock 2016-12-06 17:01:55 +0900 (0166670) @@ -3,7 +3,7 @@ PATH specs: groonga-client-model (0.9.0) activemodel - groonga-client + groonga-client (>= 0.3.2) GEM remote: https://rubygems.org/ @@ -68,7 +68,7 @@ GEM globalid (0.3.7) activesupport (>= 4.1.0) gqtp (1.0.6) - groonga-client (0.3.1) + groonga-client (0.3.2) gqtp (>= 1.0.4) groonga-command (>= 1.2.8) hashie -------------- next part -------------- HTML����������������������������... 下载