em-pg-client-helper 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/em-pg-client-helper.rb +19 -1
  2. metadata +4 -4
@@ -46,6 +46,19 @@ module PG::EM::Client::Helper
46
46
 
47
47
  # Execute code in a transaction.
48
48
  #
49
+ # Calling this method opens up a transaction (by executing `BEGIN`), and
50
+ # then runs the supplied block, passing in a transaction object which you
51
+ # can use to execute SQL commands. When the block completes, a `COMMIT`
52
+ # will automatically be executed, unless you have manually called
53
+ # `txn.commit` or `txn.rollback`. Since `db_transaction` returns a
54
+ # deferrable, you should use `#callback` to specify what to run after the
55
+ # transaction completes.
56
+ #
57
+ # If an SQL error occurs during the transaction, the block's execution
58
+ # will be aborted, a `ROLLBACK` will be executed, and the `#errback`
59
+ # block (if defined) on the deferrable will be executed (rather than the
60
+ # `#callback` block).
61
+ #
49
62
  # Arguments:
50
63
  #
51
64
  # * `db` -- A PG::EM::Client or PG::EM::ConnectionPool instance, against
@@ -79,7 +92,7 @@ module PG::EM::Client::Helper
79
92
  # decided to put in their names.
80
93
  #
81
94
  def quote_identifier(id)
82
- '"' + id.gsub(/"/, '""') + '"'
95
+ "\"#{id.gsub(/"/, '""')}\""
83
96
  end
84
97
 
85
98
  class Transaction
@@ -140,6 +153,11 @@ module PG::EM::Client::Helper
140
153
  # successfully.
141
154
  #
142
155
  def exec(sql, values=[], &blk)
156
+ unless @active
157
+ raise RuntimeError,
158
+ "Cannot execute a query in a transaction that has been closed"
159
+ end
160
+
143
161
  df = @conn.exec_defer(sql, values).
144
162
  errback { |ex| rollback(ex) }
145
163
  df.callback(&blk) if blk
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-pg-client-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-20 00:00:00.000000000 Z
12
+ date: 2014-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git-version-bump
@@ -236,7 +236,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
236
  version: '0'
237
237
  segments:
238
238
  - 0
239
- hash: -3158041732847442492
239
+ hash: -2023776752281468626
240
240
  required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  none: false
242
242
  requirements:
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  segments:
247
247
  - 0
248
- hash: -3158041732847442492
248
+ hash: -2023776752281468626
249
249
  requirements: []
250
250
  rubyforge_project:
251
251
  rubygems_version: 1.8.23