diff --git a/lib/Groonga/Commands/CreateTable.pm b/lib/Groonga/Commands/CreateTable.pm index 91b0612..95da9cb 100644 --- a/lib/Groonga/Commands/CreateTable.pm +++ b/lib/Groonga/Commands/CreateTable.pm @@ -66,8 +66,8 @@ sub _parse_arguments { _is_valid_arguments($args); - if (exists($args->{'table'})) { - $parsed_arguments{'table'} = $args->{'table'}; + if (exists($args->{'name'})) { + $parsed_arguments{'name'} = $args->{'name'}; } else { croak 'Missing a require argument "table"'; } diff --git a/lib/Groonga/Commands/Dump.pm b/lib/Groonga/Commands/Dump.pm new file mode 100644 index 0000000..f42a7e1 --- /dev/null +++ b/lib/Groonga/Commands/Dump.pm @@ -0,0 +1,115 @@ +# Copyright (C) 2022 Horimoto Yasuhiro +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +package Groonga::Commands::Delete; + +use Carp 'croak'; + +use strict; +use warnings; +use Data::Dumper; +use JSON; +my $groonga_http_client = undef; +my $command_args = ""; +my @arguments = ( + 'tables', + 'dump_plugins', + 'dump_schema', + 'dump_records', + 'dump_indexes', + 'dump_configs', + 'sort_hash_table' +); + +sub new { + my ($class, %args) = @_; + my $self = {%args}; + + $groonga_http_client = $self->{client}; + $command_args = _parse_arguments($self); + + return bless $self, $class; +} + +sub _is_valid_arguments { + my $args = shift; + + while (my ($key, $value) = each %{$args}) { + if ($key eq 'client') { + next; + } + if (!(grep {$_ eq $key} @arguments)) { + croak "Invalid arguments: ${key}"; + } + } + + return 1; #true +} + +sub _parse_arguments { + my $args = shift; + + my %parsed_arguments = (); + + _is_valid_arguments($args); + + if (exists($args->{'tables'})) { + $parsed_arguments{'tables'} = $args->{'tables'}; + } + if (exists($args->{'dump_plugins'})) { + $parsed_arguments{'dump_plugins'} = $args->{'dump_plugins'}; + } + if (exists($args->{'dump_schema'})) { + $parsed_arguments{'dump_schema'} = $args->{'dump_schema'}; + } + if (exists($args->{'dump_records'})) { + $parsed_arguments{'dump_records'} = $args->{'dump_records'}; + } + if (exists($args->{'dump_indexes'})) { + $parsed_arguments{'dump_indexes'} = $args->{'dump_indexes'}; + } + if (exists($args->{'dump_configs'})) { + $parsed_arguments{'dump_configs'} = $args->{'dump_configs'}; + } + if (exists($args->{'sort_hash_table'})) { + $parsed_arguments{'sort_hash_table'} = $args->{'sort_hash_table'}; + } + + return \%parsed_arguments; +} + +sub _parse_result { + my $result = shift; + my %result_set = (); + + if ($result == JSON::PP::true) { + $result = 1; + } else { + $result = 0; + } + print Dumper $result; + $result_set{'is_success'} = $result; + + return \%result_set; +} + +sub execute { + if (defined $groonga_http_client) { + return _parse_result($groonga_http_client->send('dump', $command_args)); + } + return; +} + +1; diff --git a/lib/Groonga/HTTP.pm b/lib/Groonga/HTTP.pm index b6f5e16..c72913b 100644 --- a/lib/Groonga/HTTP.pm +++ b/lib/Groonga/HTTP.pm @@ -27,6 +27,7 @@ use Groonga::Commands::Load; use Groonga::Commands::Status; use Groonga::Commands::Select; use Groonga::Commands::CreateTable; +use Groonga::Commands::Dump; use strict; @@ -107,6 +108,16 @@ sub create_table { return $create_table->execute; } +sub dump { + my ($client, %args) = @_; + my $dump = + Groonga::Commands::Dump->new( + client => $groonga_http_client, + %args + ); + return $dump->execute; +} + sub groonga_query_escape { my ($client, $raw_query) = @_; return Groonga::Escape->escape($raw_query); diff --git a/xt/table-create.t b/xt/create-table.t similarity index 81% rename from xt/table-create.t rename to xt/create-table.t index df90586..9ad9bb4 100644 --- a/xt/table-create.t +++ b/xt/create-table.t @@ -23,13 +23,22 @@ my $groonga = Groonga::HTTP->new(); # Create Hash Table { my $create_table_result = $groonga->create_table( - table => 'Site' + name => 'Site' ); is( $create_table_result->{'is_success'}, 1, "successed create table." ); + + my $dump_results = $groonga->dump( + tables => 'Site' + ); + is( + $dump_results[0], + "table_create Sites TABLE_HASH_KEY", + "dump returns correct results and successed create table." + ); } done_testing();