insert 0.0.1 → 0.0.2

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: b9b27be2554b0a43f13e9e654377a74458c01eea
4
- data.tar.gz: 0a5441ca52e4d398a18e23127d3f35e18e0bc50a
3
+ metadata.gz: c1e66a0f320d2c6c5aeb91f10c762a49f86750d9
4
+ data.tar.gz: b5d769bffbaee74b058ee9e9e5faad47cc556503
5
5
  SHA512:
6
- metadata.gz: caeca0c9ed447df6e9ea632163c0463be1062c6954521a8430e8a64dd19f2c4236cfc5708680f69b3f5d21006c5472ff2f6cfdf366acff94bc138e7474a3097a
7
- data.tar.gz: 70314898fa3b86be6cbe3d3584c8189e08786bd62f7cbdde6e328c1184434e06e68e9260b17d1ba5c23fc7476367bc39a16eef5ec9bb79a9705d3c46d6180097
6
+ metadata.gz: fb76886411cd1d164c7d1accd6529eb67fb129d5978f7bfd88bc1b5b6923a3ce12a71641e4037a9495ff8ae66207027886aabf80d68b81d7e4562af37eb45b3d
7
+ data.tar.gz: 1d52d0b6915fb21dc3175a799396843cc1b16c9a9ac4d088bfd9cfc73a24beb215d58d4713c859e193510da1b3f838702037db2d9fc3591375cacc12bfd7a66c
@@ -0,0 +1,9 @@
1
+ 0.0.2 / 2014-05-02
2
+
3
+ * Enhancements
4
+
5
+ * Insert#deallocate in case you can't wait until the end of the database session
6
+
7
+ 0.0.1 / 2014-05-02
8
+
9
+ initial release!
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Insert
2
2
 
3
- Super simple way to insert rows into a database
3
+ Super simple way to insert rows into a database.
4
+
5
+ Currently only supports postgres.
6
+
7
+ Currently uses prepared statements.
4
8
 
5
9
  ## Installation
6
10
 
@@ -11,6 +11,7 @@ class Insert
11
11
  end
12
12
 
13
13
  def insert(quoted_table_name, attrs)
14
+ raise "can't insert if already deallocated!" if @deallocated
14
15
  attrs = attrs.map do |k, v|
15
16
  [ k.to_s, v ]
16
17
  end.sort_by { |k, _| k }
@@ -18,6 +19,14 @@ class Insert
18
19
  connection.exec_prepared statement_for(quoted_table_name, attrs.keys), attrs.values
19
20
  end
20
21
 
22
+ def deallocate
23
+ raise "can't deallocate if already deallocated!" if @deallocated
24
+ @deallocated = true
25
+ @statements.each do |_, name|
26
+ connection.exec "DEALLOCATE #{name}"
27
+ end
28
+ end
29
+
21
30
  private
22
31
 
23
32
  def statement_for(quoted_table_name, cols)
@@ -1,3 +1,3 @@
1
1
  class Insert
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -26,4 +26,32 @@ describe Insert do
26
26
  insert.insert :dogs, age: 2, name: 'bill'
27
27
  end.to change{Dog.where(age: 2, name: 'bill').count}
28
28
  end
29
+
30
+ it "blows up without deallocate" do
31
+ expect do
32
+ Insert.new(connection).insert :dogs, age: 7
33
+ Insert.new(connection).insert :dogs, age: 7
34
+ end.to raise_error(PG::DuplicatePstatement)
35
+ end
36
+
37
+ it "can deallocate" do
38
+ a = Insert.new(connection)
39
+ b = Insert.new(connection)
40
+ expect do
41
+ a.insert :dogs, age: 7
42
+ a.deallocate
43
+ b.insert :dogs, age: 7
44
+ end.to change{Dog.count}.by(2)
45
+ end
46
+
47
+ it "won't allow insert after deallocate" do
48
+ insert.deallocate
49
+ expect{insert.insert(:dogs, age: 7)}.to raise_error(/can't.*dealloc/i)
50
+ end
51
+
52
+ it "won't allow deallocate after deallocate" do
53
+ insert.deallocate
54
+ expect{insert.deallocate}.to raise_error(/can't.*dealloc/i)
55
+ end
56
+
29
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -105,6 +105,7 @@ files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
107
  - ".travis.yml"
108
+ - CHANGELOG
108
109
  - Gemfile
109
110
  - LICENSE.txt
110
111
  - README.md