This commit is contained in:
Nikita Volkov 2023-10-16 03:54:25 +03:00
parent 7ae600f3a5
commit 6270c62cee
16 changed files with 77 additions and 27 deletions

View File

@ -172,7 +172,6 @@ test-suite tasty
build-depends:
, contravariant-extras >=0.3.5.2 && <0.4
, hasql
, QuickCheck >=2.8.1 && <3
, quickcheck-instances >=0.3.11 && <0.4
, rerebase <2
, tasty >=0.12 && <2

View File

@ -2,7 +2,7 @@
-- This module provides a low-level effectful API dealing with the connections to the database.
module Hasql.Connection
( Connection,
ConnectionError (..),
ConnectionError,
acquire,
release,
Settings,

View File

@ -6,7 +6,6 @@ module Hasql.Private.Commands
)
where
import qualified Data.ByteString as B
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy as BL
import Hasql.Private.Prelude

View File

@ -3,7 +3,6 @@
module Hasql.Private.Decoders where
import qualified Data.Aeson as Aeson
import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GenericVector
import qualified Hasql.Private.Decoders.Array as Array
import qualified Hasql.Private.Decoders.Composite as Composite
@ -11,7 +10,6 @@ import qualified Hasql.Private.Decoders.Result as Result
import qualified Hasql.Private.Decoders.Results as Results
import qualified Hasql.Private.Decoders.Row as Row
import qualified Hasql.Private.Decoders.Value as Value
import qualified Hasql.Private.Errors as Errors
import Hasql.Private.Prelude hiding (bool, maybe)
import qualified Hasql.Private.Prelude as Prelude
import qualified Network.IP.Addr as NetworkIp

View File

@ -116,8 +116,6 @@ maybe rowDec =
where
rowToInt (LibPQ.Row n) =
fromIntegral n
intToRow =
LibPQ.Row . fromIntegral
{-# INLINE single #-}
single :: Row.Row a -> Result a
@ -139,8 +137,6 @@ single rowDec =
where
rowToInt (LibPQ.Row n) =
fromIntegral n
intToRow =
LibPQ.Row . fromIntegral
{-# INLINE vector #-}
vector :: Row.Row a -> Result (Vector a)

View File

@ -12,7 +12,6 @@ module Hasql.Private.Decoders.Results where
import qualified Database.PostgreSQL.LibPQ as LibPQ
import qualified Hasql.Private.Decoders.Result as Result
import qualified Hasql.Private.Decoders.Row as Row
import Hasql.Private.Errors
import Hasql.Private.Prelude hiding (many, maybe)
import qualified Hasql.Private.Prelude as Prelude

View File

@ -2,7 +2,6 @@
-- An API of low-level IO operations.
module Hasql.Private.IO where
import qualified Data.DList as DList
import qualified Database.PostgreSQL.LibPQ as LibPQ
import qualified Hasql.Private.Commands as Commands
import qualified Hasql.Private.Decoders.Result as ResultDecoders

View File

@ -19,142 +19,212 @@ mkPTI format oid arrayOID =
-- * Constants
abstime :: PTI
abstime = mkPTI LibPQ.Binary 702 (Just 1023)
aclitem :: PTI
aclitem = mkPTI LibPQ.Binary 1033 (Just 1034)
bit :: PTI
bit = mkPTI LibPQ.Binary 1560 (Just 1561)
bool :: PTI
bool = mkPTI LibPQ.Binary 16 (Just 1000)
box :: PTI
box = mkPTI LibPQ.Binary 603 (Just 1020)
bpchar :: PTI
bpchar = mkPTI LibPQ.Binary 1042 (Just 1014)
bytea :: PTI
bytea = mkPTI LibPQ.Binary 17 (Just 1001)
char :: PTI
char = mkPTI LibPQ.Binary 18 (Just 1002)
cid :: PTI
cid = mkPTI LibPQ.Binary 29 (Just 1012)
cidr :: PTI
cidr = mkPTI LibPQ.Binary 650 (Just 651)
circle :: PTI
circle = mkPTI LibPQ.Binary 718 (Just 719)
cstring :: PTI
cstring = mkPTI LibPQ.Binary 2275 (Just 1263)
date :: PTI
date = mkPTI LibPQ.Binary 1082 (Just 1182)
daterange :: PTI
daterange = mkPTI LibPQ.Binary 3912 (Just 3913)
float4 :: PTI
float4 = mkPTI LibPQ.Binary 700 (Just 1021)
float8 :: PTI
float8 = mkPTI LibPQ.Binary 701 (Just 1022)
gtsvector :: PTI
gtsvector = mkPTI LibPQ.Binary 3642 (Just 3644)
inet :: PTI
inet = mkPTI LibPQ.Binary 869 (Just 1041)
int2 :: PTI
int2 = mkPTI LibPQ.Binary 21 (Just 1005)
int2vector :: PTI
int2vector = mkPTI LibPQ.Binary 22 (Just 1006)
int4 :: PTI
int4 = mkPTI LibPQ.Binary 23 (Just 1007)
int4range :: PTI
int4range = mkPTI LibPQ.Binary 3904 (Just 3905)
int8 :: PTI
int8 = mkPTI LibPQ.Binary 20 (Just 1016)
int8range :: PTI
int8range = mkPTI LibPQ.Binary 3926 (Just 3927)
interval :: PTI
interval = mkPTI LibPQ.Binary 1186 (Just 1187)
json :: PTI
json = mkPTI LibPQ.Binary 114 (Just 199)
jsonb :: PTI
jsonb = mkPTI LibPQ.Binary 3802 (Just 3807)
line :: PTI
line = mkPTI LibPQ.Binary 628 (Just 629)
lseg :: PTI
lseg = mkPTI LibPQ.Binary 601 (Just 1018)
macaddr :: PTI
macaddr = mkPTI LibPQ.Binary 829 (Just 1040)
money :: PTI
money = mkPTI LibPQ.Binary 790 (Just 791)
name :: PTI
name = mkPTI LibPQ.Binary 19 (Just 1003)
numeric :: PTI
numeric = mkPTI LibPQ.Binary 1700 (Just 1231)
numrange :: PTI
numrange = mkPTI LibPQ.Binary 3906 (Just 3907)
oid :: PTI
oid = mkPTI LibPQ.Binary 26 (Just 1028)
oidvector :: PTI
oidvector = mkPTI LibPQ.Binary 30 (Just 1013)
path :: PTI
path = mkPTI LibPQ.Binary 602 (Just 1019)
point :: PTI
point = mkPTI LibPQ.Binary 600 (Just 1017)
polygon :: PTI
polygon = mkPTI LibPQ.Binary 604 (Just 1027)
record :: PTI
record = mkPTI LibPQ.Binary 2249 (Just 2287)
refcursor :: PTI
refcursor = mkPTI LibPQ.Binary 1790 (Just 2201)
regclass :: PTI
regclass = mkPTI LibPQ.Binary 2205 (Just 2210)
regconfig :: PTI
regconfig = mkPTI LibPQ.Binary 3734 (Just 3735)
regdictionary :: PTI
regdictionary = mkPTI LibPQ.Binary 3769 (Just 3770)
regoper :: PTI
regoper = mkPTI LibPQ.Binary 2203 (Just 2208)
regoperator :: PTI
regoperator = mkPTI LibPQ.Binary 2204 (Just 2209)
regproc :: PTI
regproc = mkPTI LibPQ.Binary 24 (Just 1008)
regprocedure :: PTI
regprocedure = mkPTI LibPQ.Binary 2202 (Just 2207)
regtype :: PTI
regtype = mkPTI LibPQ.Binary 2206 (Just 2211)
reltime :: PTI
reltime = mkPTI LibPQ.Binary 703 (Just 1024)
text :: PTI
text = mkPTI LibPQ.Binary 25 (Just 1009)
tid :: PTI
tid = mkPTI LibPQ.Binary 27 (Just 1010)
time :: PTI
time = mkPTI LibPQ.Binary 1083 (Just 1183)
timestamp :: PTI
timestamp = mkPTI LibPQ.Binary 1114 (Just 1115)
timestamptz :: PTI
timestamptz = mkPTI LibPQ.Binary 1184 (Just 1185)
timetz :: PTI
timetz = mkPTI LibPQ.Binary 1266 (Just 1270)
tinterval :: PTI
tinterval = mkPTI LibPQ.Binary 704 (Just 1025)
tsquery :: PTI
tsquery = mkPTI LibPQ.Binary 3615 (Just 3645)
tsrange :: PTI
tsrange = mkPTI LibPQ.Binary 3908 (Just 3909)
tstzrange :: PTI
tstzrange = mkPTI LibPQ.Binary 3910 (Just 3911)
tsvector :: PTI
tsvector = mkPTI LibPQ.Binary 3614 (Just 3643)
txid_snapshot :: PTI
txid_snapshot = mkPTI LibPQ.Binary 2970 (Just 2949)
textUnknown :: PTI
textUnknown = mkPTI LibPQ.Text 705 (Just 705)
binaryUnknown :: PTI
binaryUnknown = mkPTI LibPQ.Binary 705 (Just 705)
uuid :: PTI
uuid = mkPTI LibPQ.Binary 2950 (Just 2951)
varbit :: PTI
varbit = mkPTI LibPQ.Binary 1562 (Just 1563)
varchar :: PTI
varchar = mkPTI LibPQ.Binary 1043 (Just 1015)
void :: PTI
void = mkPTI LibPQ.Binary 2278 Nothing
xid :: PTI
xid = mkPTI LibPQ.Binary 28 (Just 1011)
xml :: PTI
xml = mkPTI LibPQ.Binary 142 (Just 143)

View File

@ -46,7 +46,7 @@ import Data.Either as Exports
import Data.Fixed as Exports
import Data.Foldable as Exports hiding (toList)
import Data.Function as Exports hiding (id, (.))
import Data.Functor as Exports
import Data.Functor as Exports hiding (unzip)
import Data.Functor.Compose as Exports
import Data.Functor.Contravariant as Exports
import Data.Functor.Contravariant.Divisible as Exports

View File

@ -1,6 +1,5 @@
module Hasql.Private.Session where
import qualified Database.PostgreSQL.LibPQ as LibPQ
import qualified Hasql.Private.Connection as Connection
import qualified Hasql.Private.Decoders.Result as Decoders.Result
import qualified Hasql.Private.Decoders.Results as Decoders.Results
@ -9,7 +8,6 @@ import qualified Hasql.Private.Encoders.Params as Encoders.Params
import Hasql.Private.Errors
import qualified Hasql.Private.IO as IO
import Hasql.Private.Prelude
import qualified Hasql.Private.Settings as Settings
import qualified Hasql.Statement as Statement
-- |

View File

@ -3,11 +3,11 @@ module Main where
import qualified Data.Vector as F
import qualified Hasql.Connection as A
import qualified Hasql.Decoders as D
import qualified Hasql.Encoders as E
import qualified Hasql.Session as B
import qualified Hasql.Statement as C
import Prelude
main :: IO ()
main =
do
Right connection <- acquireConnection

View File

@ -9,16 +9,17 @@ import qualified Main.Connection as Connection
import qualified Main.DSL as DSL
import Main.Prelude hiding (assert)
import qualified Main.Statements as Statements
import qualified Test.QuickCheck as QuickCheck
import Test.QuickCheck.Instances
import Test.QuickCheck.Instances ()
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck
import Test.Tasty.Runners
main :: IO ()
main =
defaultMain tree
tree :: TestTree
tree =
localOption (NumThreads 1)
$ testGroup

View File

@ -1,8 +1,6 @@
module Main.Connection where
import qualified Hasql.Connection as HC
import qualified Hasql.Session
import qualified Hasql.Statement as HQ
import Main.Prelude
with :: (HC.Connection -> IO a) -> IO (Either HC.ConnectionError a)

View File

@ -8,10 +8,7 @@ module Main.DSL
where
import qualified Hasql.Connection as HC
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
import qualified Hasql.Session
import qualified Hasql.Statement as HQ
import Main.Prelude
type Session =

View File

@ -1,10 +1,8 @@
module Main.Statements where
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
import qualified Hasql.Statement as HQ
import Main.Prelude
import qualified Main.Prelude as Prelude
plain :: ByteString -> HQ.Statement () ()
plain sql =

View File

@ -1,13 +1,11 @@
module Main where
import qualified Hasql.Connection
import qualified Hasql.Decoders
import qualified Hasql.Encoders
import qualified Hasql.Session
import qualified Hasql.Statement
import qualified Main.Statements as Statements
import Prelude
main :: IO ()
main =
acquire >>= use
where