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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a726eb5a922ba00e842ae5128897f44ebc348ed
4
- data.tar.gz: 0d3d601ffb7c5bbecfd3c6f80a55905b434559e7
3
+ metadata.gz: 55b4dfa8a269c3f83308ef19acaae60bb29198f6
4
+ data.tar.gz: d217309dc244aa67205082d81b5306d38cd02df7
5
5
  SHA512:
6
- metadata.gz: 5a55318fc2253b2244ffe7ec3fa88496903ed9f42171b7b1b036f002ffd69e3e7781836678e5e7a1362cc2f20e79c44e3f2c6b69c5dbf5114ec26eade980c578
7
- data.tar.gz: b09c8a6e7d4449746105721e8cc3903f7c18cd2231f2359c5e749cdc43f3af5c5c01a3197356d8e04d14c060b20ec2b6bc550ee912c32c723f8590e5650768e8
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 /crate_ruby/fork` )
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
@@ -0,0 +1,7 @@
1
+ # coding: UTF-8
2
+
3
+ === 0.0.5
4
+
5
+ Enhancements:
6
+
7
+ * #execute now supports parameter substitution
@@ -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
- req.body = {"stmt" => sql}.to_json
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
@@ -1,3 +1,3 @@
1
1
  module CrateRuby
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -78,14 +78,20 @@ describe CrateRuby::Client do
78
78
  end
79
79
 
80
80
  describe '#execute' do
81
- let(:TABLE_NAME) { "post" }
81
+ let(:table_name) { "post" }
82
82
 
83
83
  after do
84
- client.execute("drop TABLE #{TABLE_NAME}").should be_true
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 #{TABLE_NAME} (id int)").should be_true
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.drop_table "posts"
111
- client.drop_table "comments"
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
- client.insert('posts', id: SecureRandom.uuid, title: "Test" )
134
- sleep(1)
135
- result_set = client.execute("Select * from posts where title = 'Test'")
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
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-04-18 00:00:00.000000000 Z
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