module Hasql.Private.PTI where

import qualified Database.PostgreSQL.LibPQ as LibPQ
import Hasql.Private.Prelude hiding (bool)

-- | A Postgresql type info
data PTI = PTI {PTI -> OID
ptiOID :: !OID, PTI -> Maybe OID
ptiArrayOID :: !(Maybe OID)}

-- | A Word32 and a LibPQ representation of an OID
data OID = OID {OID -> Word32
oidWord32 :: !Word32, OID -> Oid
oidPQ :: !LibPQ.Oid, OID -> Format
oidFormat :: !LibPQ.Format}

mkOID :: LibPQ.Format -> Word32 -> OID
mkOID :: Format -> Word32 -> OID
mkOID Format
format Word32
x =
  Word32 -> Oid -> Format -> OID
OID Word32
x ((CUInt -> Oid
LibPQ.Oid forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) Word32
x) Format
format

mkPTI :: LibPQ.Format -> Word32 -> Maybe Word32 -> PTI
mkPTI :: Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
format Word32
oid Maybe Word32
arrayOID =
  OID -> Maybe OID -> PTI
PTI (Format -> Word32 -> OID
mkOID Format
format Word32
oid) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Format -> Word32 -> OID
mkOID Format
format) Maybe Word32
arrayOID)

-- * Constants

abstime :: PTI
abstime = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
702 (forall a. a -> Maybe a
Just Word32
1023)

aclitem :: PTI
aclitem = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1033 (forall a. a -> Maybe a
Just Word32
1034)

bit :: PTI
bit = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1560 (forall a. a -> Maybe a
Just Word32
1561)

bool :: PTI
bool = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
16 (forall a. a -> Maybe a
Just Word32
1000)

box :: PTI
box = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
603 (forall a. a -> Maybe a
Just Word32
1020)

bpchar :: PTI
bpchar = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1042 (forall a. a -> Maybe a
Just Word32
1014)

bytea :: PTI
bytea = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
17 (forall a. a -> Maybe a
Just Word32
1001)

char :: PTI
char = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
18 (forall a. a -> Maybe a
Just Word32
1002)

cid :: PTI
cid = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
29 (forall a. a -> Maybe a
Just Word32
1012)

cidr :: PTI
cidr = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
650 (forall a. a -> Maybe a
Just Word32
651)

circle :: PTI
circle = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
718 (forall a. a -> Maybe a
Just Word32
719)

cstring :: PTI
cstring = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2275 (forall a. a -> Maybe a
Just Word32
1263)

date :: PTI
date = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1082 (forall a. a -> Maybe a
Just Word32
1182)

daterange :: PTI
daterange = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3912 (forall a. a -> Maybe a
Just Word32
3913)

float4 :: PTI
float4 = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
700 (forall a. a -> Maybe a
Just Word32
1021)

float8 :: PTI
float8 = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
701 (forall a. a -> Maybe a
Just Word32
1022)

gtsvector :: PTI
gtsvector = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3642 (forall a. a -> Maybe a
Just Word32
3644)

inet :: PTI
inet = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
869 (forall a. a -> Maybe a
Just Word32
1041)

int2 :: PTI
int2 = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
21 (forall a. a -> Maybe a
Just Word32
1005)

int2vector :: PTI
int2vector = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
22 (forall a. a -> Maybe a
Just Word32
1006)

int4 :: PTI
int4 = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
23 (forall a. a -> Maybe a
Just Word32
1007)

int4range :: PTI
int4range = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3904 (forall a. a -> Maybe a
Just Word32
3905)

int8 :: PTI
int8 = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
20 (forall a. a -> Maybe a
Just Word32
1016)

int8range :: PTI
int8range = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3926 (forall a. a -> Maybe a
Just Word32
3927)

interval :: PTI
interval = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1186 (forall a. a -> Maybe a
Just Word32
1187)

json :: PTI
json = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
114 (forall a. a -> Maybe a
Just Word32
199)

jsonb :: PTI
jsonb = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3802 (forall a. a -> Maybe a
Just Word32
3807)

line :: PTI
line = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
628 (forall a. a -> Maybe a
Just Word32
629)

lseg :: PTI
lseg = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
601 (forall a. a -> Maybe a
Just Word32
1018)

macaddr :: PTI
macaddr = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
829 (forall a. a -> Maybe a
Just Word32
1040)

money :: PTI
money = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
790 (forall a. a -> Maybe a
Just Word32
791)

name :: PTI
name = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
19 (forall a. a -> Maybe a
Just Word32
1003)

numeric :: PTI
numeric = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1700 (forall a. a -> Maybe a
Just Word32
1231)

numrange :: PTI
numrange = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3906 (forall a. a -> Maybe a
Just Word32
3907)

oid :: PTI
oid = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
26 (forall a. a -> Maybe a
Just Word32
1028)

oidvector :: PTI
oidvector = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
30 (forall a. a -> Maybe a
Just Word32
1013)

path :: PTI
path = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
602 (forall a. a -> Maybe a
Just Word32
1019)

point :: PTI
point = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
600 (forall a. a -> Maybe a
Just Word32
1017)

polygon :: PTI
polygon = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
604 (forall a. a -> Maybe a
Just Word32
1027)

record :: PTI
record = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2249 (forall a. a -> Maybe a
Just Word32
2287)

refcursor :: PTI
refcursor = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1790 (forall a. a -> Maybe a
Just Word32
2201)

regclass :: PTI
regclass = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2205 (forall a. a -> Maybe a
Just Word32
2210)

regconfig :: PTI
regconfig = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3734 (forall a. a -> Maybe a
Just Word32
3735)

regdictionary :: PTI
regdictionary = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3769 (forall a. a -> Maybe a
Just Word32
3770)

regoper :: PTI
regoper = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2203 (forall a. a -> Maybe a
Just Word32
2208)

regoperator :: PTI
regoperator = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2204 (forall a. a -> Maybe a
Just Word32
2209)

regproc :: PTI
regproc = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
24 (forall a. a -> Maybe a
Just Word32
1008)

regprocedure :: PTI
regprocedure = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2202 (forall a. a -> Maybe a
Just Word32
2207)

regtype :: PTI
regtype = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2206 (forall a. a -> Maybe a
Just Word32
2211)

reltime :: PTI
reltime = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
703 (forall a. a -> Maybe a
Just Word32
1024)

text :: PTI
text = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
25 (forall a. a -> Maybe a
Just Word32
1009)

tid :: PTI
tid = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
27 (forall a. a -> Maybe a
Just Word32
1010)

time :: PTI
time = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1083 (forall a. a -> Maybe a
Just Word32
1183)

timestamp :: PTI
timestamp = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1114 (forall a. a -> Maybe a
Just Word32
1115)

timestamptz :: PTI
timestamptz = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1184 (forall a. a -> Maybe a
Just Word32
1185)

timetz :: PTI
timetz = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1266 (forall a. a -> Maybe a
Just Word32
1270)

tinterval :: PTI
tinterval = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
704 (forall a. a -> Maybe a
Just Word32
1025)

tsquery :: PTI
tsquery = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3615 (forall a. a -> Maybe a
Just Word32
3645)

tsrange :: PTI
tsrange = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3908 (forall a. a -> Maybe a
Just Word32
3909)

tstzrange :: PTI
tstzrange = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3910 (forall a. a -> Maybe a
Just Word32
3911)

tsvector :: PTI
tsvector = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
3614 (forall a. a -> Maybe a
Just Word32
3643)

txid_snapshot :: PTI
txid_snapshot = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2970 (forall a. a -> Maybe a
Just Word32
2949)

unknown :: PTI
unknown = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Text Word32
705 (forall a. a -> Maybe a
Just Word32
705)

uuid :: PTI
uuid = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2950 (forall a. a -> Maybe a
Just Word32
2951)

varbit :: PTI
varbit = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1562 (forall a. a -> Maybe a
Just Word32
1563)

varchar :: PTI
varchar = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
1043 (forall a. a -> Maybe a
Just Word32
1015)

void :: PTI
void = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
2278 forall a. Maybe a
Nothing

xid :: PTI
xid = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
28 (forall a. a -> Maybe a
Just Word32
1011)

xml :: PTI
xml = Format -> Word32 -> Maybe Word32 -> PTI
mkPTI Format
LibPQ.Binary Word32
142 (forall a. a -> Maybe a
Just Word32
143)