crate_ruby 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/history.txt +7 -0
- data/lib/crate_ruby/client.rb +5 -2
- data/lib/crate_ruby/version.rb +1 -1
- data/spec/crate_ruby/client_spec.rb +16 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55b4dfa8a269c3f83308ef19acaae60bb29198f6
|
4
|
+
data.tar.gz: d217309dc244aa67205082d81b5306d38cd02df7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f64c08fd539c392fe4d471e40841b9bd3d2124858c9e0f767c649f9faeb6a335ccb3859eb5519904dbf219185c3d1def0e6eb092d0be20cb51dcc864a3126d8
|
7
|
+
data.tar.gz: b255048105ccc16c4cb3c208b0b6d9e1bdef02980e4af4f3e7eb1f4887313432da3d33b109902a6806e72266198c6fc94df2432ca6eb1442b882b921a2e7e057
|
data/README.md
CHANGED
@@ -29,6 +29,12 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
result.cols
|
31
31
|
=> ["id", "my_column", "my_integer_col"]
|
32
|
+
|
33
|
+
|
34
|
+
#### Using parameter substitution
|
35
|
+
|
36
|
+
client.execute("INSERT INTO posts (id, title, tags) VALUES (\$1, \$2, \$3)",
|
37
|
+
[1, "My life with crate", ['awesome', 'freaky']])
|
32
38
|
|
33
39
|
### Up/Downloading data
|
34
40
|
digest = Digest::SHA1.file(file_path).hexdigest
|
@@ -54,7 +60,7 @@ To run the tests start up the crate server first
|
|
54
60
|
|
55
61
|
## Contributing
|
56
62
|
|
57
|
-
1. Fork it ( `http://github.com/crate
|
63
|
+
1. Fork it ( `http://github.com/crate/crate_ruby/fork` )
|
58
64
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
65
|
3. Add some tests
|
60
66
|
4. Commit your changes (`git commit -am 'Add some feature'`)
|
data/history.txt
ADDED
data/lib/crate_ruby/client.rb
CHANGED
@@ -71,11 +71,14 @@ module CrateRuby
|
|
71
71
|
|
72
72
|
# Executes a SQL statement against the Crate HTTP REST endpoint.
|
73
73
|
# @param [String] sql statement to execute
|
74
|
+
# @param [Array] args Array of values used for parameter substitution
|
74
75
|
# @return [ResultSet]
|
75
|
-
def execute(sql)
|
76
|
+
def execute(sql, args = nil)
|
76
77
|
@logger.debug sql
|
77
78
|
req = Net::HTTP::Post.new("/_sql", initheader = {'Content-Type' => 'application/json'})
|
78
|
-
|
79
|
+
body = {"stmt" => sql}
|
80
|
+
body.merge!({'args' => args}) if args
|
81
|
+
req.body = body.to_json
|
79
82
|
response = request(req)
|
80
83
|
@logger.debug response.body
|
81
84
|
success = case response.code
|
data/lib/crate_ruby/version.rb
CHANGED
@@ -78,14 +78,20 @@ describe CrateRuby::Client do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
describe '#execute' do
|
81
|
-
let(:
|
81
|
+
let(:table_name) { "post" }
|
82
82
|
|
83
83
|
after do
|
84
|
-
client.execute("drop TABLE #{
|
84
|
+
client.execute("drop TABLE #{table_name}").should be_true
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should create a new table' do
|
88
|
-
client.execute("CREATE TABLE #{
|
88
|
+
client.execute("CREATE TABLE #{table_name} (id int)").should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should allow parameter substitution' do
|
92
|
+
client.execute("CREATE TABLE #{table_name} (id int, title string, tags array(string) )").should be_true
|
93
|
+
client.execute("INSERT INTO #{table_name} (id, title, tags) VALUES (\$1, \$2, \$3)",
|
94
|
+
[1, "My life with crate", ['awesome', 'freaky']]).should be_true
|
89
95
|
end
|
90
96
|
|
91
97
|
end
|
@@ -107,8 +113,9 @@ describe CrateRuby::Client do
|
|
107
113
|
end
|
108
114
|
|
109
115
|
after do
|
110
|
-
client.
|
111
|
-
|
116
|
+
client.tables.each do |table|
|
117
|
+
client.drop_table table
|
118
|
+
end
|
112
119
|
end
|
113
120
|
|
114
121
|
it 'should return all user tables as an array of string values' do
|
@@ -130,9 +137,10 @@ describe CrateRuby::Client do
|
|
130
137
|
|
131
138
|
it 'should insert the record' do
|
132
139
|
expect do
|
133
|
-
|
134
|
-
|
135
|
-
|
140
|
+
id = SecureRandom.uuid
|
141
|
+
client.insert('posts', id: id, title: "Test")
|
142
|
+
client.refresh_table('posts')
|
143
|
+
result_set = client.execute("Select * from posts where id = '#{id}'")
|
136
144
|
result_set.rowcount.should eq 1
|
137
145
|
end.not_to raise_exception
|
138
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crate_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Klocker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- crate_ruby.gemspec
|
68
|
+
- history.txt
|
68
69
|
- lib/crate_ruby.rb
|
69
70
|
- lib/crate_ruby/client.rb
|
70
71
|
- lib/crate_ruby/error.rb
|