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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d67a62c833d6468ecbb753a54f592f2b9ecb295fb2db7eb943c25184c481e4c0
4
- data.tar.gz: 32e9c5c68c6469bd1613e4b0881b22a7545616f63dffb08f4a6ba04d2ad28fb3
3
+ metadata.gz: 689e8e2af4e7e8c941ed6f14937288a3e080f822b71ee22938898ac0a15f5277
4
+ data.tar.gz: 9693bc5e2476794d9f60feb70e80c821596ec18a4e71993d45aee65a26a152f1
5
5
  SHA512:
6
- metadata.gz: 563a4e08014aedec4c7a2321f78a22534e8250d6f1b4e5189ce1482b3348c5b8a25f411fcc059ece8984eece9cb53dcdc30d56691dde0856ef74aa14c61c18cc
7
- data.tar.gz: 3e99489831703bb5aa978923fa2430bcab133ce8e2c4bcfbc84472a699aa09c70935f7d76945eee0cc5d90575c8ff2fe37a3268754e00f723143bdca2179c796
6
+ metadata.gz: 10c90d7568c1c6ed34b9cb04e4a2e4a9af0ed6bb788ea6ec88f206b807468091e9d541f6dfc79ae7eb3d5e90b92e33a12718aae1c4d7e6977352331a499fbee1
7
+ data.tar.gz: 6b945c42734e68a599b2d32d825fa6c9d8b61a7eb1175086afae237c21fb58d30d4753eb916a69716a2c0c3a43dd51da34d655fb6b145352814d5256aa137d9d
@@ -15,9 +15,6 @@ name: Lint Code Base
15
15
  # Start the job on all push #
16
16
  #############################
17
17
  on:
18
- push:
19
- branches-ignore: [master]
20
- # Remove the line above to run when pushing to master
21
18
  pull_request:
22
19
  branches: [master]
23
20
 
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ensql (0.6.3)
4
+ ensql (0.6.4)
5
5
  connection_pool (>= 0.9.3, < 3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- ensql (0.6.3)
4
+ ensql (0.6.4)
5
5
  connection_pool (>= 0.9.3, < 3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- ensql (0.6.3)
4
+ ensql (0.6.4)
5
5
  connection_pool (>= 0.9.3, < 3)
6
6
 
7
7
  GEM
@@ -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
- @result_type_map = @pool.with { |c| PG::BasicTypeMapForResults.new(c) }
53
- @query_type_map = @pool.with { |c| build_query_type_map(c) }
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 = @result_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 = @query_type_map[value.class]
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) ? @query_type_map.send(coder, value) : coder
150
+ coder.is_a?(Symbol) ? query_type_map.send(coder, value) : coder
128
151
  end
129
152
 
130
- # Ensure encoders are set up for old versions of the pg gem
131
- def build_query_type_map(connection)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Ensql
4
4
  # Gem version
5
- VERSION = "0.6.3"
5
+ VERSION = "0.6.4"
6
6
  # Versions of activerecord compatible with the {ActiveRecordAdapter}
7
7
  SUPPORTED_ACTIVERECORD_VERSIONS = [">= 5.0", "< 6.2"].freeze
8
8
  # Versions of sequel compatible with the {SequelAdapter}
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.3
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 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool