ensql 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +0 -3
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/gemfiles/maintained.gemfile.lock +1 -1
- data/gemfiles/minimum.gemfile.lock +1 -1
- data/lib/ensql/postgres_adapter.rb +31 -14
- data/lib/ensql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 689e8e2af4e7e8c941ed6f14937288a3e080f822b71ee22938898ac0a15f5277
|
4
|
+
data.tar.gz: 9693bc5e2476794d9f60feb70e80c821596ec18a4e71993d45aee65a26a152f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10c90d7568c1c6ed34b9cb04e4a2e4a9af0ed6bb788ea6ec88f206b807468091e9d541f6dfc79ae7eb3d5e90b92e33a12718aae1c4d7e6977352331a499fbee1
|
7
|
+
data.tar.gz: 6b945c42734e68a599b2d32d825fa6c9d8b61a7eb1175086afae237c21fb58d30d4753eb916a69716a2c0c3a43dd51da34d655fb6b145352814d5256aa137d9d
|
data/.github/workflows/lint.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.6.4] - unreleased
|
4
|
+
|
5
|
+
- Exposes `PostgresAdapter#query_type_map` to extend PG type mapping.
|
6
|
+
- Defers building type maps for PostgreSQL connections, to avoid bugs with ActiveRecord.
|
7
|
+
|
3
8
|
## [0.6.3] - 2021-03-11
|
4
9
|
|
5
10
|
- Supports transaction flow control using any flavour SQL with `Ensql.transaction` and `Ensql.rollback!`.
|
data/Gemfile.lock
CHANGED
@@ -14,7 +14,8 @@ module Ensql
|
|
14
14
|
# [connection_pool gem](https://github.com/mperham/connection_pool).
|
15
15
|
#
|
16
16
|
# This adapter is much faster and offers much better PostgreSQL specific
|
17
|
-
# parameter interpolation than the framework adapters.
|
17
|
+
# parameter interpolation than the framework adapters. See {query_type_map}
|
18
|
+
# for options.
|
18
19
|
#
|
19
20
|
# @example
|
20
21
|
# # Use with ActiveRecord's connection pool
|
@@ -49,8 +50,30 @@ module Ensql
|
|
49
50
|
def initialize(pool)
|
50
51
|
@pool = pool
|
51
52
|
@quoter = PG::TextEncoder::QuotedLiteral.new
|
52
|
-
|
53
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
# A map for encoding Ruby objects into PostgreSQL literals based on their
|
56
|
+
# class. You can add additional class mappings to suit your needs. See
|
57
|
+
# https://rubydoc.info/gems/pg/PG/BasicTypeRegistry for details of adding
|
58
|
+
# your own encoders and decoders.
|
59
|
+
#
|
60
|
+
# # Encode any `IPAddr` objects for interpolation using the `InetEncoder`.
|
61
|
+
# Ensql.adapter.query_type_map[IPAddr] = InetEncoder.new
|
62
|
+
#
|
63
|
+
# # Deserialize `inet` columns as IPAddr objects.
|
64
|
+
# PG::BasicTypeRegistry.register_type(0, 'inet', InetEncoder, InetDecoder)
|
65
|
+
#
|
66
|
+
# @return [PG::TypeMapByClass]
|
67
|
+
def query_type_map
|
68
|
+
@query_type_map ||= @pool.with do |connection|
|
69
|
+
map = PG::BasicTypeMapForQueries.new(connection)
|
70
|
+
# Ensure encoders are set up for old versions of the pg gem
|
71
|
+
map[Date] ||= PG::TextEncoder::Date.new
|
72
|
+
map[Time] ||= PG::TextEncoder::TimestampWithoutTimeZone.new
|
73
|
+
map[Hash] ||= PG::TextEncoder::JSON.new
|
74
|
+
map[BigDecimal] ||= NumericEncoder.new
|
75
|
+
map
|
76
|
+
end
|
54
77
|
end
|
55
78
|
|
56
79
|
# @visibility private
|
@@ -106,7 +129,7 @@ module Ensql
|
|
106
129
|
|
107
130
|
def fetch_result(sql)
|
108
131
|
execute(sql) do |res|
|
109
|
-
res.type_map =
|
132
|
+
res.type_map = result_type_map
|
110
133
|
yield res
|
111
134
|
end
|
112
135
|
end
|
@@ -122,19 +145,13 @@ module Ensql
|
|
122
145
|
end
|
123
146
|
|
124
147
|
def encoder_for(value)
|
125
|
-
coder =
|
148
|
+
coder = query_type_map[value.class]
|
126
149
|
# Handle the weird case where coder can be a method name
|
127
|
-
coder.is_a?(Symbol) ?
|
150
|
+
coder.is_a?(Symbol) ? query_type_map.send(coder, value) : coder
|
128
151
|
end
|
129
152
|
|
130
|
-
|
131
|
-
|
132
|
-
map = PG::BasicTypeMapForQueries.new(connection)
|
133
|
-
map[Date] ||= PG::TextEncoder::Date.new
|
134
|
-
map[Time] ||= PG::TextEncoder::TimestampWithoutTimeZone.new
|
135
|
-
map[Hash] ||= PG::TextEncoder::JSON.new
|
136
|
-
map[BigDecimal] ||= NumericEncoder.new
|
137
|
-
map
|
153
|
+
def result_type_map
|
154
|
+
@result_type_map ||= @pool.with { |c| PG::BasicTypeMapForResults.new(c) }
|
138
155
|
end
|
139
156
|
end
|
140
157
|
|
data/lib/ensql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ensql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Fone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|