mini_sql 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3897b303ad7bfbcd8e892ae599ece87b6124af5e8fbe497e961d320a2f71375
4
- data.tar.gz: 8ce1ca1561b98fa9763811d0d4ba719bb5310c691494857ae430daa0779a632b
3
+ metadata.gz: 0fc60087b4254ce21f8cbe17e3ecbfd980f93a95bbe258f9a7a4d78d7a057d7b
4
+ data.tar.gz: e2f13c9b9c8f4e3f91570d405a59ba3cfc9c742dd8ecbaeebd75a3b4190fe085
5
5
  SHA512:
6
- metadata.gz: 95839fd2df00baf38ba432b05c8c61a9baf067edc193d00e4b7808a8bd4ee15168971d435943ffda04326ea4bec6ab4af324c7135eea2fa5f426d0ecdb357038
7
- data.tar.gz: b7c0be1a8ef4b394543edb0ef80b0103d224b1aa47462a17b81c83e0449e47bd419878805fbcd3de3c53d83c68fc171527aae8e70d27840edfa6705afe1325e7
6
+ metadata.gz: 41fb7cdb0ea9365a733629fb1f1c863e3153c077d03754c123249cea1da8edf5ce3e8fd19b95f5922b61cfd4742d87f1431b92b25c974b6a438fa4b449a8b915
7
+ data.tar.gz: 0e0b2b47a5ed734a4d1bf3d54ce827f27df9a59c886e83913c2eb20abefa8fc88528ee25988ee69042f996a52fd54259160914fb6c56e57f44456b39e6fc361e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mini_sql (0.1.4)
4
+ mini_sql (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,6 +3,7 @@
3
3
  module MiniSql
4
4
  class Connection
5
5
  attr_reader :raw_connection
6
+ attr_reader :type_map
6
7
 
7
8
  def self.default_deserializer_cache
8
9
  @deserializer_cache ||= DeserializerCache.new
@@ -24,14 +25,17 @@ module MiniSql
24
25
  # @param raw_connection [PG::Connection] an active connection to PG
25
26
  # @param deserializer_cache [MiniSql::DeserializerCache] a cache of field names to deserializer, can be nil
26
27
  # @param type_map [PG::TypeMap] a type mapper for all results returned, can be nil
27
- def initialize(raw_connection, deserializer_cache: nil, type_map: nil, param_encoder: nil)
28
+ def initialize(raw_connection, deserializer_cache: nil, param_encoder: nil)
28
29
  # TODO adapter to support other databases
29
30
  @raw_connection = raw_connection
30
31
  @deserializer_cache = deserializer_cache || Connection.default_deserializer_cache
31
- @type_map = type_map || Connection.type_map(raw_connection)
32
32
  @param_encoder = param_encoder || InlineParamEncoder.new(self)
33
33
  end
34
34
 
35
+ def type_map
36
+ @type_map ||= self.class.type_map(raw_connection)
37
+ end
38
+
35
39
  # Returns a flat array containing all results.
36
40
  # Note, if selecting multiple columns array will be flattened
37
41
  #
@@ -40,7 +44,7 @@ module MiniSql
40
44
  # @return [Object] a flat array containing all results
41
45
  def query_single(sql, *params)
42
46
  result = run(sql, params)
43
- result.type_map = @type_map
47
+ result.type_map = type_map
44
48
  if result.nfields == 1
45
49
  result.column_values(0)
46
50
  else
@@ -63,7 +67,7 @@ module MiniSql
63
67
 
64
68
  def query(sql, *params)
65
69
  result = run(sql, params)
66
- result.type_map = @type_map
70
+ result.type_map = type_map
67
71
  @deserializer_cache.materialize(result)
68
72
  ensure
69
73
  result.clear if result
@@ -78,7 +82,7 @@ module MiniSql
78
82
 
79
83
  def query_hash(sql, *params)
80
84
  result = run(sql, params)
81
- result.type_map = @type_map
85
+ result.type_map = type_map
82
86
  result.to_a
83
87
  ensure
84
88
  result.clear
@@ -1,3 +1,3 @@
1
1
  module MiniSql
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron