pgtk 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pgtk/pool.rb +13 -1
- data/lib/pgtk/version.rb +1 -1
- data/test/test_pool.rb +6 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b886c68a58dedba95aa0c86bf94d544532ea8652c65beb93bb852c4d9f06eb
|
4
|
+
data.tar.gz: 60727fc4ddc2050fdeec8a8a4aa638dc9695635724f0e28f55306b9d86ea7b43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439d320d935e09c0b3f554dce0ae44c576a9d966b51afd02c90770d4ec5ff4a29b05eebde0ba3716dbd1ac3168513d4aa17d22236994765ee11eb5066b8f0791
|
7
|
+
data.tar.gz: f604f0b90ad7628ef216467d0cc3a25b694713aca8b4e000202d88882980e3d9a741bc3819da98b38a9aaad5d541e442a6dc8eb69b870e51ba46e5ff14938550
|
data/lib/pgtk/pool.rb
CHANGED
@@ -106,6 +106,17 @@ class Pgtk::Pool
|
|
106
106
|
# end
|
107
107
|
# end
|
108
108
|
#
|
109
|
+
# When the query is too long it's convenient to use an array to specify it:
|
110
|
+
#
|
111
|
+
# pool.exec(
|
112
|
+
# [
|
113
|
+
# 'SELECT * FROM book',
|
114
|
+
# 'LEFT JOIN user ON user.id = book.owner',
|
115
|
+
# 'WHERE user.login = $1 AND book.title = $2'
|
116
|
+
# ],
|
117
|
+
# ['yegor256', 'Elegant Objects']
|
118
|
+
# )
|
119
|
+
#
|
109
120
|
# More details about +exec_params+, which is called here, you can find
|
110
121
|
# here: https://www.rubydoc.info/gems/pg/0.17.1/PG%2FConnection:exec_params
|
111
122
|
def exec(query, args = [], result = 0)
|
@@ -145,7 +156,8 @@ class Pgtk::Pool
|
|
145
156
|
|
146
157
|
def exec(query, args = [], result = 0)
|
147
158
|
start = Time.now
|
148
|
-
|
159
|
+
sql = query.is_a?(Array) ? query.join(' ') : query
|
160
|
+
out = @conn.exec_params(sql, args, result) do |res|
|
149
161
|
if block_given?
|
150
162
|
yield res
|
151
163
|
else
|
data/lib/pgtk/version.rb
CHANGED
data/test/test_pool.rb
CHANGED
@@ -48,7 +48,10 @@ class TestPool < Minitest::Test
|
|
48
48
|
id = pool.transaction do |t|
|
49
49
|
t.exec('DELETE FROM book')
|
50
50
|
t.exec(
|
51
|
-
|
51
|
+
[
|
52
|
+
'INSERT INTO book (title)',
|
53
|
+
'VALUES ($1) RETURNING id'
|
54
|
+
],
|
52
55
|
['Object Thinking']
|
53
56
|
)[0]['id'].to_i
|
54
57
|
end
|
@@ -81,7 +84,8 @@ class TestPool < Minitest::Test
|
|
81
84
|
port: yaml['pgsql']['port'],
|
82
85
|
dbname: yaml['pgsql']['dbname'],
|
83
86
|
user: yaml['pgsql']['user'],
|
84
|
-
password: yaml['pgsql']['password']
|
87
|
+
password: yaml['pgsql']['password'],
|
88
|
+
log: nil
|
85
89
|
)
|
86
90
|
pool.start(1)
|
87
91
|
yield pool
|