em-pg-client-helper 2.0.6 → 2.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54a166e4a003830acb87084c9ce7e3e89247adc0
4
- data.tar.gz: 6fd87c473b76cb510cbee6d46e5c161c08c1b783
3
+ metadata.gz: 00dae568e9a3fbcee2f9f9d02f1567c29d3b407d
4
+ data.tar.gz: b9baf2122794e3f7b9b820f7e452d0538574b64a
5
5
  SHA512:
6
- metadata.gz: 542c67c1cc93d7bcdd2c871edfd553ced9aa2de42906822b31931662344521c6a7e6697f56d7c70aa3fc84431410991ac08f9b0d135c6d0fdf97ef85193b8c58
7
- data.tar.gz: 15c39dd9ba382f9ee0a267e2406f63c6171fb4438a5b205128406a3203facd2e9197066d79b26a9fe0a002c63df8b87dd0404f020b27006e34d5a5ad9acf979c
6
+ metadata.gz: f4e0290bba50452b458df0ad181c5b6010c19934a420c132c00625580c7430aa9aea093ef6d9df790104cdad03be27988c1c7603c6f24aaee498482a83992281
7
+ data.tar.gz: c4dc5ba9b3d490e51dfd4a246f910d042778626db74895468759ddfba58c6b21af7fbe9bb940c2ce3e4628eb19d66a884f965550bf9d8547e2de2734263d989c
@@ -240,6 +240,13 @@ class PG::EM::Client::Helper::Transaction
240
240
  def bulk_insert(tbl, columns, rows, &blk)
241
241
  columns.map!(&:to_sym)
242
242
 
243
+ if rows.empty?
244
+ return EM::Completion.new.tap do |df|
245
+ df.callback(&blk) if blk
246
+ df.succeed(0)
247
+ end
248
+ end
249
+
243
250
  EM::Completion.new.tap do |df|
244
251
  @dg.add(df)
245
252
  df.callback(&blk) if blk
@@ -2,15 +2,6 @@ require_relative './spec_helper'
2
2
 
3
3
  describe "PG::EM::Client::Helper#db_bulk_insert" do
4
4
  let(:mock_conn) { double(PG::EM::Client) }
5
- let(:fast_query) do
6
- 'INSERT INTO "foo" ("bar", "baz") ' +
7
- '(SELECT * FROM (VALUES (1, \'x\'), (3, \'y\')) ' +
8
- 'AS src ("bar", "baz") ' +
9
- 'WHERE NOT EXISTS ' +
10
- '(SELECT 1 FROM "foo" AS dst ' +
11
- 'WHERE (src."bar"=dst."bar" AND src."baz"=dst."baz")))'
12
- end
13
-
14
5
  def expect_unique_indexes_query(indexes)
15
6
  indexes.map! do |i|
16
7
  idxid = rand(1000000).to_s
@@ -27,12 +18,17 @@ describe "PG::EM::Client::Helper#db_bulk_insert" do
27
18
  expect(dbl = double).to receive(:results).with(2)
28
19
  expect(dbl).to_not receive(:errback)
29
20
 
21
+ query = 'INSERT INTO "foo" ("bar", "baz") ' +
22
+ '(SELECT * FROM (VALUES (1, \'x\'), (3, \'y\')) ' +
23
+ 'AS src ("bar", "baz") ' +
24
+ 'WHERE NOT EXISTS ' +
25
+ '(SELECT 1 FROM "foo" AS dst ' +
26
+ 'WHERE (src."bar"=dst."bar" AND src."baz"=dst."baz")))'
27
+
30
28
  in_em do
31
29
  expect_query("BEGIN")
32
30
  expect_unique_indexes_query([[:bar, :baz]])
33
- expect_query(fast_query,
34
- [], 0.001, :succeed, Struct.new(:cmd_tuples).new(2)
35
- )
31
+ expect_query(query, [], 0.001, :succeed, Struct.new(:cmd_tuples).new(2))
36
32
  expect_query("COMMIT")
37
33
 
38
34
  db_bulk_insert(mock_conn, "foo", [:bar, :baz], [[1, "x"], [3, "y"]]) do |count|
@@ -60,4 +56,18 @@ describe "PG::EM::Client::Helper#db_bulk_insert" do
60
56
  end.errback { dbl.errback; EM.stop }
61
57
  end
62
58
  end
59
+
60
+ it "does nothing with an empty set of data" do
61
+ expect(dbl = double).to receive(:results).with(0)
62
+ expect(dbl).to_not receive(:errback)
63
+
64
+ in_em do
65
+ expect_query("BEGIN")
66
+ expect_query("COMMIT")
67
+ db_bulk_insert(mock_conn, "foo", [:bar, :baz], []) do |count|
68
+ dbl.results(count)
69
+ EM.stop
70
+ end.errback { dbl.errback; EM.stop }
71
+ end
72
+ end
63
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-pg-client-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-pg-client