groonga-client 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/groonga-client +114 -0
- data/doc/text/news.md +7 -0
- data/groonga-client.gemspec +5 -4
- data/lib/groonga/client/protocol/http/synchronous.rb +2 -1
- data/lib/groonga/client/version.rb +1 -1
- data/test/response/test-table-list.rb +28 -3
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837550f5d3d1eeec4eb0e92880c66f897f40fd12
|
4
|
+
data.tar.gz: ffe2005c27525c1b162603c903551aac1bf0bfe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d301825f48a0157aadc8f7772e502514816057584af795abd71f9433e2e4aaf09b7a8379974533e2023f5560e0d50e33a370e9a469b1095e7a0bf54f291ca614
|
7
|
+
data.tar.gz: 14af40e9d242b61acb46f8ebe28886c4118a0b0a64a9920fb7e237a522c8909004ddcabed86e104740a214248f545b19e78ee40990195426feeff03ae2e272a7
|
data/bin/groonga-client
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
#
|
4
|
+
# Copyright (C) 2015 Kouhei Sutou <kou@clear-code.com>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
|
20
|
+
require "ostruct"
|
21
|
+
require "optparse"
|
22
|
+
require "json"
|
23
|
+
|
24
|
+
require "groonga/command/parser"
|
25
|
+
|
26
|
+
require "groonga/client"
|
27
|
+
|
28
|
+
def default_port(protocol)
|
29
|
+
case protocol
|
30
|
+
when :http
|
31
|
+
10041
|
32
|
+
when :gqtp
|
33
|
+
10043
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def run_command(client, command)
|
38
|
+
response = client.execute(command)
|
39
|
+
case command.output_type
|
40
|
+
when :json
|
41
|
+
puts(JSON.pretty_generate([response.header, response.body]))
|
42
|
+
when :xml
|
43
|
+
puts(response.raw)
|
44
|
+
else
|
45
|
+
puts(response.body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
options = OpenStruct.new
|
50
|
+
options.protocol = :http
|
51
|
+
options.host = "localhost"
|
52
|
+
options.port = nil
|
53
|
+
|
54
|
+
parser = OptionParser.new
|
55
|
+
parser.version = Groonga::Client::VERSION
|
56
|
+
parser.banner += " GROONGA_COMMAND_FILE1 GROONGA_COMMAND_FILE2 ..."
|
57
|
+
parser.separator("")
|
58
|
+
parser.separator("Connection:")
|
59
|
+
available_protocols = [:http, :gqtp]
|
60
|
+
parser.on("--protocol=PROTOCOL", [:http, :gqtp],
|
61
|
+
"Protocol to connect to Groonga server.",
|
62
|
+
"[#{available_protocols.join(", ")}]",
|
63
|
+
"(#{options.protocol})") do |protocol|
|
64
|
+
options.protocol = protocol
|
65
|
+
end
|
66
|
+
parser.on("--host=HOST",
|
67
|
+
"Groonga server to be connected.",
|
68
|
+
"(#{options.host})") do |host|
|
69
|
+
options.host = host
|
70
|
+
end
|
71
|
+
parser.on("--port=PORT", Integer,
|
72
|
+
"Port number of Groonga server to be connected.",
|
73
|
+
"(auto)") do |port|
|
74
|
+
options.port = port
|
75
|
+
end
|
76
|
+
command_file_paths = parser.parse!(ARGV)
|
77
|
+
|
78
|
+
options.port ||= default_port(options.protocol)
|
79
|
+
|
80
|
+
client = Groonga::Client.new(:protocol => options.protocol,
|
81
|
+
:host => options.host,
|
82
|
+
:port => options.port,
|
83
|
+
:backend => :synchronous)
|
84
|
+
parser = Groonga::Command::Parser.new
|
85
|
+
parser.on_command do |command|
|
86
|
+
run_command(client, command)
|
87
|
+
end
|
88
|
+
|
89
|
+
parser.on_load_columns do |command, columns|
|
90
|
+
command[:columns] ||= columns.join(",")
|
91
|
+
end
|
92
|
+
values = []
|
93
|
+
parser.on_load_value do |_, value|
|
94
|
+
values << value
|
95
|
+
end
|
96
|
+
parser.on_load_complete do |command|
|
97
|
+
command[:values] ||= Yajl::Encoder.encode(values)
|
98
|
+
run_command(client, command)
|
99
|
+
values.clear
|
100
|
+
end
|
101
|
+
|
102
|
+
if command_file_paths.empty?
|
103
|
+
$stdin.each_line do |line|
|
104
|
+
parser << line
|
105
|
+
end
|
106
|
+
else
|
107
|
+
command_file_paths.each do |command_file_path|
|
108
|
+
File.open(command_file_path) do |command_file|
|
109
|
+
command_file.each_line do |line|
|
110
|
+
parser << line
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/doc/text/news.md
CHANGED
data/groonga-client.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
# Copyright (C) 2014-2015 Kouhei Sutou <kou@clear-code.com>
|
5
5
|
#
|
6
6
|
# This library is free software; you can redistribute it and/or
|
7
7
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -43,12 +43,13 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.files += Dir.glob("lib/**/*.rb")
|
44
44
|
spec.files += Dir.glob("doc/text/*")
|
45
45
|
spec.test_files += Dir.glob("test/**/*")
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
Dir.chdir("bin") do
|
47
|
+
spec.executables = Dir.glob("*")
|
48
|
+
end
|
49
49
|
|
50
50
|
spec.add_runtime_dependency("gqtp", ">= 1.0.4")
|
51
51
|
spec.add_runtime_dependency("groonga-command", ">= 1.0.8")
|
52
|
+
spec.add_runtime_dependency("groonga-command-parser")
|
52
53
|
|
53
54
|
spec.add_development_dependency("bundler")
|
54
55
|
spec.add_development_dependency("rake")
|
@@ -97,7 +97,8 @@ module Groonga
|
|
97
97
|
command[:values] = raw_values
|
98
98
|
request = Net::HTTP::Post.new(path, headers)
|
99
99
|
request.content_type = "application/json"
|
100
|
-
request.
|
100
|
+
request.content_length = raw_values.bytesize
|
101
|
+
request.body_stream = StringIO.new(raw_values)
|
101
102
|
http.request(request)
|
102
103
|
else
|
103
104
|
http.get(command.to_uri_format, headers)
|
@@ -4,9 +4,34 @@ class TestResponseTableList < Test::Unit::TestCase
|
|
4
4
|
include TestResponseHelper
|
5
5
|
|
6
6
|
def test_table_list
|
7
|
-
header = [
|
8
|
-
|
9
|
-
|
7
|
+
header = [
|
8
|
+
0,
|
9
|
+
1372430096.70991,
|
10
|
+
0.000522851943969727,
|
11
|
+
]
|
12
|
+
columns = [
|
13
|
+
["id", "UInt32"],
|
14
|
+
["name", "ShortText"],
|
15
|
+
["path", "ShortText"],
|
16
|
+
["flags", "ShortText"],
|
17
|
+
["domain", "ShortText"],
|
18
|
+
["range", "ShortText"],
|
19
|
+
["default_tokenizer", "ShortText"],
|
20
|
+
["normalizer", "ShortText"],
|
21
|
+
]
|
22
|
+
body = [
|
23
|
+
columns,
|
24
|
+
[
|
25
|
+
256,
|
26
|
+
"Test",
|
27
|
+
"/tmp/test.db.0000100",
|
28
|
+
"TABLE_HASH_KEY|PERSISTENT",
|
29
|
+
nil,
|
30
|
+
nil,
|
31
|
+
nil,
|
32
|
+
nil,
|
33
|
+
],
|
34
|
+
]
|
10
35
|
raw_response = [header, body].to_json
|
11
36
|
|
12
37
|
response = parse_raw_response("table_list", raw_response)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Haruka Yoshihara
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.0.8
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: groonga-command-parser
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: bundler
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,7 +161,8 @@ email:
|
|
147
161
|
- yshr04hrk@gmail.com
|
148
162
|
- kou@clear-code.com
|
149
163
|
- tfortress58@gmail.com
|
150
|
-
executables:
|
164
|
+
executables:
|
165
|
+
- groonga-client
|
151
166
|
extensions: []
|
152
167
|
extra_rdoc_files: []
|
153
168
|
files:
|
@@ -155,6 +170,7 @@ files:
|
|
155
170
|
- Gemfile
|
156
171
|
- README.md
|
157
172
|
- Rakefile
|
173
|
+
- bin/groonga-client
|
158
174
|
- doc/text/news.md
|
159
175
|
- groonga-client.gemspec
|
160
176
|
- lib/groonga/client.rb
|