flounder 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/flounder.gemspec +1 -1
- data/lib/flounder/entity.rb +17 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebf8d5e68827d9962affb51d05cf5cd404c73c98
|
4
|
+
data.tar.gz: 22f1840346a7f36442e93e58b8295e0d5c718358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6590b22ad34ae153be4d8d56709ca6f4d1f42dfab14908fd713bd4b81123ee5583bf61fddb6743a73c22cb405683e8c1bdf296381b64a4ade1fef432d5ad1c6f
|
7
|
+
data.tar.gz: a9e0b470deae3ce0edd4f0f33b583e479246ceeb078c8d9191bc464610cbb476a3034978b987d42fa3d828fb40dfbd975c151ea610da1fe16f4b35a88836a218
|
data/flounder.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "flounder"
|
5
|
-
s.version = '0.7.
|
5
|
+
s.version = '0.7.1'
|
6
6
|
s.summary = "Flounder is a way to write SQL simply in Ruby. It deals with everything BUT object relational mapping. "
|
7
7
|
s.email = "kaspar.schiess@technologyastronauts.ch"
|
8
8
|
s.homepage = "https://bitbucket.org/technologyastronauts/laboratory_flounder"
|
data/lib/flounder/entity.rb
CHANGED
@@ -59,17 +59,25 @@ module Flounder
|
|
59
59
|
|
60
60
|
# Insert or update.
|
61
61
|
#
|
62
|
-
# TODO Envelop in transaction.
|
63
|
-
# Not sure yet where the right level of abstraction is to
|
64
|
-
# insert START TRANSACTION/COMMIT TRANSACTION.
|
65
|
-
#
|
66
62
|
def insdate fields, hash, &inserted
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
with_transaction do
|
64
|
+
found = where(hash.select { |k, _| fields.include?(k) }).first
|
65
|
+
if found
|
66
|
+
update(hash).where(:id => found.id)
|
67
|
+
else
|
68
|
+
insert(hash, &inserted)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def with_transaction &block
|
74
|
+
result = nil
|
75
|
+
domain.connection_pool.with_connection do |conn|
|
76
|
+
conn.exec 'START TRANSACTION'
|
77
|
+
result = block.call
|
78
|
+
conn.exec 'COMMIT TRANSACTION'
|
72
79
|
end
|
80
|
+
result
|
73
81
|
end
|
74
82
|
|
75
83
|
# Temporarily creates a new entity that is available as if it was declared
|