insert 0.0.1 → 0.0.2
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/CHANGELOG +9 -0
- data/README.md +5 -1
- data/lib/insert.rb +9 -0
- data/lib/insert/version.rb +1 -1
- data/spec/insert_spec.rb +28 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e66a0f320d2c6c5aeb91f10c762a49f86750d9
|
4
|
+
data.tar.gz: b5d769bffbaee74b058ee9e9e5faad47cc556503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb76886411cd1d164c7d1accd6529eb67fb129d5978f7bfd88bc1b5b6923a3ce12a71641e4037a9495ff8ae66207027886aabf80d68b81d7e4562af37eb45b3d
|
7
|
+
data.tar.gz: 1d52d0b6915fb21dc3175a799396843cc1b16c9a9ac4d088bfd9cfc73a24beb215d58d4713c859e193510da1b3f838702037db2d9fc3591375cacc12bfd7a66c
|
data/CHANGELOG
ADDED
data/README.md
CHANGED
data/lib/insert.rb
CHANGED
@@ -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)
|
data/lib/insert/version.rb
CHANGED
data/spec/insert_spec.rb
CHANGED
@@ -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.
|
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
|