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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mini_sql/connection.rb +9 -5
- data/lib/mini_sql/version.rb +1 -1
- 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: 0fc60087b4254ce21f8cbe17e3ecbfd980f93a95bbe258f9a7a4d78d7a057d7b
|
4
|
+
data.tar.gz: e2f13c9b9c8f4e3f91570d405a59ba3cfc9c742dd8ecbaeebd75a3b4190fe085
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41fb7cdb0ea9365a733629fb1f1c863e3153c077d03754c123249cea1da8edf5ce3e8fd19b95f5922b61cfd4742d87f1431b92b25c974b6a438fa4b449a8b915
|
7
|
+
data.tar.gz: 0e0b2b47a5ed734a4d1bf3d54ce827f27df9a59c886e83913c2eb20abefa8fc88528ee25988ee69042f996a52fd54259160914fb6c56e57f44456b39e6fc361e
|
data/Gemfile.lock
CHANGED
data/lib/mini_sql/connection.rb
CHANGED
@@ -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,
|
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 =
|
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 =
|
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 =
|
85
|
+
result.type_map = type_map
|
82
86
|
result.to_a
|
83
87
|
ensure
|
84
88
|
result.clear
|
data/lib/mini_sql/version.rb
CHANGED