[Groonga-commit] ranguba/rroonga at bf8631d [master] Added :max_records option to grndump

Back to archive index

TakiuchiGenki null+****@clear*****
Sun Feb 21 16:12:09 JST 2016


TakiuchiGenki	2016-02-21 16:12:09 +0900 (Sun, 21 Feb 2016)

  New Revision: bf8631d10d37a6d4b51376b69958d8695ca29ed9
  https://github.com/ranguba/rroonga/commit/bf8631d10d37a6d4b51376b69958d8695ca29ed9

  Merged 69481d6: Merge pull request #115 from genki/max_records

  Message:
    Added :max_records option to grndump

  Modified files:
    bin/grndump
    lib/groonga/dumper.rb

  Modified: bin/grndump (+8 -0)
===================================================================
--- bin/grndump    2016-02-21 00:21:08 +0900 (24d6cd8)
+++ bin/grndump    2016-02-21 16:12:09 +0900 (1640cff)
@@ -29,6 +29,7 @@ options.dump_schema = true
 options.dump_indexes = true
 options.dump_tables = true
 options.order_by = "id"
+options.max_records = -1
 option_parser = OptionParser.new do |parser|
   parser.version = Groonga::BINDINGS_VERSION
   parser.banner += " DB_PATH"
@@ -79,6 +80,12 @@ option_parser = OptionParser.new do |parser|
             "(#{options.order_by})") do |type|
     options.order_by = type
   end
+
+  parser.on("--max-records=NUMBER",
+            "max NUMBER of records to dump",
+            "(#{options.max_records})") do |number|
+    options.max_records = number.to_i
+  end
 end
 args = option_parser.parse!(ARGV)
 
@@ -99,6 +106,7 @@ dumper_options = {
   :tables => options.tables,
   :exclude_tables => options.exclude_tables,
   :order_by => options.order_by,
+  :max_records => options.max_records,
 }
 database_dumper = Groonga::DatabaseDumper.new(dumper_options)
 database_dumper.dump

  Modified: lib/groonga/dumper.rb (+3 -1)
===================================================================
--- lib/groonga/dumper.rb    2016-02-21 00:21:08 +0900 (92b6e98)
+++ lib/groonga/dumper.rb    2016-02-21 16:12:09 +0900 (51d7fbc)
@@ -666,6 +666,7 @@ module Groonga
       @have_output = !@output.nil?
       @output ||= Dumper.default_output
       @error_output = @options[:error_output]
+      @max_records = @options[:max_records]
     end
 
     def dump
@@ -709,7 +710,8 @@ module Groonga
       when Groonga::Array, Groonga::Hash
         order_by = nil if order_by == :key
       end
-      @table.each(:order_by => order_by) do |record|
+      limit = @options[:max_records]
+      @table.each(:order_by => order_by, :limit => limit) do |record|
         write(",\n")
         values = columns.collect do |column|
           resolve_value(record, column, column[record.id])
-------------- next part --------------
HTML����������������������������...
Télécharger 



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