FEATURE: add support for custom type maps

FEATURE: add support for custom type maps

support for custom type maps when using the pg backend using:

MiniSql::Connections.get(pg_connection, type_map: custom_type_map)
diff --git a/.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml b/.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
index 0a15cd9..f74aa30 100644
--- a/.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
+++ b/.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
@@ -1,8 +1,9 @@
 require:
   - rubocop-discourse
+  - rubocop-rspec
 
 AllCops:
-  TargetRubyVersion: 2.4
+  TargetRubyVersion: 2.6
   DisabledByDefault: true
   Exclude:
     - "db/schema.rb"
@@ -12,6 +13,14 @@ AllCops:
     - "public/**/*"
     - "plugins/**/gems/**/*"
 
+Discourse:
+  Enabled: true
+
+Discourse/NoChdir:
+  Exclude:
+    - 'spec/**/*' # Specs are run sequentially, so chdir can be used
+    - 'plugins/*/spec/**/*'
+
 # Prefer &&/|| over and/or.
 Style/AndOr:
   Enabled: true
@@ -19,11 +28,6 @@ Style/AndOr:
 Style/FrozenStringLiteralComment:
   Enabled: true
 
-# Do not use braces for hash literals when they are the last argument of a
-# method call.
-Style/BracesAroundHashParameters:
-  Enabled: true
-
 # Align `when` with `case`.
 Layout/CaseIndentation:
   Enabled: true
@@ -132,15 +136,6 @@ Style/Semicolon:
 Style/RedundantReturn:
   Enabled: true
 
-DiscourseCops/NoChdir:
-  Enabled: true
-  Exclude:
-    - 'spec/**/*' # Specs are run sequentially, so chdir can be used
-    - 'plugins/*/spec/**/*'
-
-DiscourseCops/NoURIEscapeEncode:
-  Enabled: true
-
 Style/GlobalVars:
   Enabled: true
   Severity: warning
@@ -149,3 +144,212 @@ Style/GlobalVars:
     - 'script/**/*'
     - 'spec/**/*.rb'
     - 'plugins/*/spec/**/*'
+
+# Specs
+
+RSpec/AnyInstance:
+  Enabled: false # To be decided
+
+RSpec/AroundBlock:
+  Enabled: true
+
+RSpec/BeforeAfterAll:
+  Enabled: false # To be decided
+
+RSpec/ContextMethod:
+  Enabled: false # TODO
+
+RSpec/ContextWording:
+  Enabled: false # To be decided
+
+RSpec/DescribeClass:
+  Enabled: false # To be decided
+
+RSpec/DescribeMethod:
+  Enabled: true
+
+RSpec/DescribeSymbol:
+  Enabled: false # To be decided
+
+RSpec/DescribedClass:
+  Enabled: false # To be decided
+
+RSpec/DescribedClassModuleWrapping:
+  Enabled: false # To be decided
+
+RSpec/EmptyExampleGroup:
+  Enabled: true
+
+RSpec/EmptyLineAfterExample:
+  Enabled: false # TODO
+
+RSpec/EmptyLineAfterExampleGroup:
+  Enabled: false # TODO
+
+RSpec/EmptyLineAfterFinalLet:
+  Enabled: false # TODO
+
+RSpec/EmptyLineAfterHook:
+  Enabled: false # TODO
+
+RSpec/EmptyLineAfterSubject:
+  Enabled: false # TODO
+
+RSpec/ExampleLength:
+  Enabled: false # To be decided
+
+RSpec/ExampleWithoutDescription:
+  Enabled: true
+
+RSpec/ExampleWording:
+  Enabled: false # TODO
+
+RSpec/ExpectActual:
+  Enabled: true
+
+RSpec/ExpectChange:
+  Enabled: false # To be decided
+
+RSpec/ExpectInHook:
+  Enabled: false # To be decided
+
+RSpec/ExpectOutput:
+  Enabled: true
+
+RSpec/FilePath:
+  Enabled: false # To be decided
+
+RSpec/Focus:
+  Enabled: true
+
+RSpec/HookArgument:
+  Enabled: false # TODO
+
+RSpec/HooksBeforeExamples:
+  Enabled: false # TODO
+
+RSpec/ImplicitBlockExpectation:
+  Enabled: true
+
+RSpec/ImplicitExpect:
+  Enabled: false # To be decided
+
+RSpec/ImplicitSubject:
+  Enabled: false # To be decided
+
+RSpec/InstanceSpy:
+  Enabled: true
+
+RSpec/InstanceVariable:
+  Enabled: false # TODO
+
+RSpec/InvalidPredicateMatcher:
+  Enabled: true
+
+RSpec/ItBehavesLike:
+  Enabled: true
+
+RSpec/IteratedExpectation:
+  Enabled: false # To be decided
+
+RSpec/LeadingSubject:
+  Enabled: false # TODO
+
+RSpec/LeakyConstantDeclaration:
+  Enabled: false # To be decided
+
+RSpec/LetBeforeExamples:
+  Enabled: false # TODO
+
+RSpec/LetSetup:
+  Enabled: false # TODO
+
+RSpec/MessageChain:
+  Enabled: true
+
+RSpec/MessageSpies:
+  Enabled: true
+
+RSpec/MissingExampleGroupArgument:
+  Enabled: true
+
+RSpec/MultipleDescribes:
+  Enabled: false # TODO
+
+RSpec/MultipleSubjects:
+  Enabled: true
+
+RSpec/NamedSubject:
+  Enabled: false # To be decided
+
+RSpec/NestedGroups:
+  Enabled: false # To be decided
+
+RSpec/OverwritingSetup:
+  Enabled: true
+
+RSpec/ReceiveCounts:
+  Enabled: true
+
+RSpec/ReceiveNever:
+  Enabled: true
+
+RSpec/RepeatedDescription:
+  Enabled: false # TODO
+
+RSpec/RepeatedExample:
+  Enabled: false # TODO
+
+RSpec/RepeatedExampleGroupBody:
+  Enabled: false # TODO
+
+RSpec/RepeatedExampleGroupDescription:
+  Enabled: false # TODO
+
+RSpec/ReturnFromStub:
+  Enabled: true
+
+RSpec/ScatteredSetup:
+  Enabled: false # TODO
+
+RSpec/SharedContext:
+  Enabled: true
+
+RSpec/SharedExamples:
+  Enabled: true
+
+RSpec/SingleArgumentMessageChain:
+  Enabled: true
+
+RSpec/SubjectStub:
+  Enabled: true
+
+RSpec/UnspecifiedException:
+  Enabled: true
+
+RSpec/VerifiedDoubles:
+  Enabled: true
+
+RSpec/VoidExpect:
+  Enabled: true
+
+RSpec/Yield:
+  Enabled: true
+
+Capybara/CurrentPathExpectation:
+  Enabled: true
+
+Capybara/FeatureMethods:
+  Enabled: true
+
+FactoryBot/AttributeDefinedStatically:
+  Enabled: true
+
+FactoryBot/CreateList:
+  Enabled: true
+
+FactoryBot/FactoryClassName:
+  Enabled: true
+
+Rails/HttpStatus:
+  Enabled: true
diff --git a/CHANGELOG b/CHANGELOG
index 6bf36a9..a8e6767 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+2020-04-07 - 0.2.5
+
+- Added support for custom type maps with Postgres connections
+
 2019-01-16 - 0.2.4
 
 - Fixed symbol param encoder
diff --git a/README.md b/README.md
index 3414b15..64473e6 100644
--- a/README.md
+++ b/README.md
@@ -124,6 +124,39 @@ MiniSql is careful to always clear results as soon as possible.
 
 MiniSql's default type mapper prefers treating `timestamp without time zone` columns as utc. This is done to ensure widest amount of compatability and is a departure from the default in the PG 1.0 gem. If you wish to amend behavior feel free to pass in a custom type_map.
 
+## Custom type maps
+
+When using Postgres, native type mapping implementation is used. This is roughly
+implemented as:
+
+`‍``ruby
+type_map = PG::BasicTypeMapForResults.new(conn)
+# additional specific decoders
+`‍``
+
+Initializing the basic type map for Postgres can be a costly operation. You may
+wish to amend the type mapper so for example you only return strings:
+
+`‍``
+# maybe you do not want Integer
+p cnn.query("select a 1").first.a
+"1"
+`‍``
+
+To specify a different type mapper for your results use:
+
+`‍``
+MiniSql::Connections.get(pg_connection, type_map: custom_type_map)
+`‍``
+
+In the case of Rails you can opt to use the type mapper Rails uses with:
+
+`‍``
+pg_cnn = ActiveRecord::Base.connection.raw_connection
+mini_sql_cnn = MiniSql::Connection.get(pg_cnn, type_map: pg_cnn.type_map_for_results)
+`‍``
+
+Note the type mapper for Rails may miss some of the mapping MiniSql ships with such as `IPAddr`, MiniSql is also careful to use the very efficient TimestampUtc decoders where available.
 
 ## I want more features!
 
diff --git a/lib/mini_sql/postgres/connection.rb b/lib/mini_sql/postgres/connection.rb
index e11fc28..affcc4a 100644
--- a/lib/mini_sql/postgres/connection.rb
+++ b/lib/mini_sql/postgres/connection.rb
@@ -39,6 +39,7 @@ module MiniSql
         @raw_connection = raw_connection
         @deserializer_cache = (args && args[:deserializer_cache]) || self.class.default_deserializer_cache
         @param_encoder = (args && args[:param_encoder]) || InlineParamEncoder.new(self)
+        @type_map = args && args[:type_map]
       end
 
       def type_map
diff --git a/lib/mini_sql/version.rb b/lib/mini_sql/version.rb
index 79131be..f9f5666 100644
--- a/lib/mini_sql/version.rb
+++ b/lib/mini_sql/version.rb
@@ -1,4 +1,4 @@
 # frozen_string_literal: true
 module MiniSql
-  VERSION = "0.2.4"
+  VERSION = "0.2.5"
 end
diff --git a/test/mini_sql/postgres/connection_test.rb b/test/mini_sql/postgres/connection_test.rb
index 6d21754..d7ad749 100644
--- a/test/mini_sql/postgres/connection_test.rb
+++ b/test/mini_sql/postgres/connection_test.rb

[... diff too long, it was truncated ...]

GitHub sha: 7a2b379a