0 | module Postgres.Data.PostgresType
15 | data Oid : Type where
19 | (MkOid x) == (MkOid y) = x == y
22 | show (MkOid oid) = show oid
27 | oidToInt : Oid -> Int
28 | oidToInt (MkOid x) = x
37 | data PType = PInteger
54 | show PInteger = "Integer"
55 | show PDouble = "Double"
57 | show PBoolean = "Boolean"
60 | show PDatetime = "DateTime"
61 | show PString = "String"
65 | show (PArray t) = (show t) ++ "[]"
66 | show (POther x) = "?" ++ x
67 | show (PUnknown (MkOid oid)) = "Oid: " ++ (show oid)
70 | data Nullability = Nullable | NonNullable
73 | data PColType : PType -> Type where
74 | MkColType : (nullable: Nullability) -> (pt : PType) -> PColType pt
77 | Show (PColType t) where
78 | show (MkColType _ x) = show x
81 | pType : PColType t -> PType
82 | pType (MkColType _ t) = t
85 | nullable : PColType t -> Bool
86 | nullable (MkColType Nullable _) = True
87 | nullable (MkColType NonNullable _) = False
90 | makeNullable : PColType t -> PColType t
91 | makeNullable (MkColType _ t) = MkColType Nullable t
98 | data FormatCode = Text | Binary
101 | Show FormatCode where
103 | show Binary = "Binary"
110 | data TypeDictionary : Type where
111 | MkTypeDictionary : List (Oid, PType) -> TypeDictionary
118 | (.types) : TypeDictionary -> List (Oid, PType)
119 | (.types) (MkTypeDictionary xs) = xs
124 | types : TypeDictionary -> List (Oid, PType)
125 | types (MkTypeDictionary xs) = xs
128 | empty : TypeDictionary
129 | empty = MkTypeDictionary []
134 | typeDictionary : List (Oid, PType) -> TypeDictionary
135 | typeDictionary xs = MkTypeDictionary (sortBy (compare `on` oidToInt . fst) xs)
140 | lookup : Oid -> TypeDictionary -> PType
141 | lookup oid = maybe (PUnknown oid) id . lookup oid . types
144 | Show TypeDictionary where
145 | show = concat . intersperse "\n" . map showTuple . types
147 | showTuple : (Oid, PType) -> String
148 | showTuple (oid, type) = (show oid) ++ ": " ++ (show type)