module Hasql.TH.Extraction.PrimitiveType where import Hasql.TH.Prelude hiding (bit, fromList, sortBy) import PostgresqlSyntax.Ast data PrimitiveType = BoolPrimitiveType | Int2PrimitiveType | Int4PrimitiveType | Int8PrimitiveType | Float4PrimitiveType | Float8PrimitiveType | NumericPrimitiveType | CharPrimitiveType | TextPrimitiveType | ByteaPrimitiveType | DatePrimitiveType | TimestampPrimitiveType | TimestamptzPrimitiveType | TimePrimitiveType | TimetzPrimitiveType | IntervalPrimitiveType | UuidPrimitiveType | InetPrimitiveType | JsonPrimitiveType | JsonbPrimitiveType simpleTypename :: SimpleTypename -> Either Text PrimitiveType simpleTypename = \case GenericTypeSimpleTypename GenericType a -> GenericType -> Either Text PrimitiveType genericType GenericType a NumericSimpleTypename Numeric a -> forall {a}. IsString a => Numeric -> Either a PrimitiveType numeric Numeric a BitSimpleTypename Bit a -> forall {a} {p} {b}. IsString a => p -> Either a b bit Bit a CharacterSimpleTypename Character a -> forall {p} {a}. p -> Either a PrimitiveType character Character a ConstDatetimeSimpleTypename ConstDatetime a -> forall {a}. ConstDatetime -> Either a PrimitiveType constDatetime ConstDatetime a ConstIntervalSimpleTypename Either (Maybe Interval) Iconst a -> forall a b. b -> Either a b Right PrimitiveType IntervalPrimitiveType genericType :: GenericType -> Either Text PrimitiveType genericType (GenericType TypeFunctionName a Maybe Attrs b Maybe TypeModifiers c) = case Maybe Attrs b of Just Attrs _ -> forall a b. a -> Either a b Left Text "Type attributes are not supported" Maybe Attrs Nothing -> case Maybe TypeModifiers c of Just TypeModifiers _ -> forall a b. a -> Either a b Left Text "Type modifiers are not supported" Maybe TypeModifiers Nothing -> TypeFunctionName -> Either Text PrimitiveType ident TypeFunctionName a numeric :: Numeric -> Either a PrimitiveType numeric = \case Numeric IntNumeric -> forall a b. b -> Either a b Right PrimitiveType Int4PrimitiveType Numeric IntegerNumeric -> forall a b. b -> Either a b Right PrimitiveType Int4PrimitiveType Numeric SmallintNumeric -> forall a b. b -> Either a b Right PrimitiveType Int2PrimitiveType Numeric BigintNumeric -> forall a b. b -> Either a b Right PrimitiveType Int8PrimitiveType Numeric RealNumeric -> forall a b. b -> Either a b Right PrimitiveType Float4PrimitiveType FloatNumeric Maybe Iconst a -> case Maybe Iconst a of Just Iconst _ -> forall a b. a -> Either a b Left a "Modifier on FLOAT is not supported" Maybe Iconst Nothing -> forall a b. b -> Either a b Right PrimitiveType Float4PrimitiveType Numeric DoublePrecisionNumeric -> forall a b. b -> Either a b Right PrimitiveType Float8PrimitiveType DecimalNumeric Maybe TypeModifiers a -> case Maybe TypeModifiers a of Just TypeModifiers _ -> forall a b. a -> Either a b Left a "Modifiers on DECIMAL are not supported" Maybe TypeModifiers Nothing -> forall a b. b -> Either a b Right PrimitiveType NumericPrimitiveType DecNumeric Maybe TypeModifiers a -> case Maybe TypeModifiers a of Just TypeModifiers _ -> forall a b. a -> Either a b Left a "Modifiers on DEC are not supported" Maybe TypeModifiers Nothing -> forall a b. b -> Either a b Right PrimitiveType NumericPrimitiveType NumericNumeric Maybe TypeModifiers a -> case Maybe TypeModifiers a of Just TypeModifiers _ -> forall a b. a -> Either a b Left a "Modifiers on NUMERIC are not supported" Maybe TypeModifiers Nothing -> forall a b. b -> Either a b Right PrimitiveType NumericPrimitiveType Numeric BooleanNumeric -> forall a b. b -> Either a b Right PrimitiveType BoolPrimitiveType bit :: p -> Either a b bit p _ = forall a b. a -> Either a b Left a "Bit codec is not supported" character :: p -> Either a PrimitiveType character p _ = forall a b. b -> Either a b Right PrimitiveType CharPrimitiveType constDatetime :: ConstDatetime -> Either a PrimitiveType constDatetime = \case TimestampConstDatetime Maybe Iconst _ Maybe Timezone a -> if Maybe Timezone -> Timezone tz Maybe Timezone a then forall a b. b -> Either a b Right PrimitiveType TimestamptzPrimitiveType else forall a b. b -> Either a b Right PrimitiveType TimestampPrimitiveType TimeConstDatetime Maybe Iconst _ Maybe Timezone a -> if Maybe Timezone -> Timezone tz Maybe Timezone a then forall a b. b -> Either a b Right PrimitiveType TimetzPrimitiveType else forall a b. b -> Either a b Right PrimitiveType TimePrimitiveType where tz :: Maybe Timezone -> Timezone tz = \case Just Timezone a -> Timezone a Maybe Timezone Nothing -> Timezone False ident :: TypeFunctionName -> Either Text PrimitiveType ident = \case QuotedIdent Text a -> forall {a}. (Eq a, IsString a, Semigroup a) => a -> Either a PrimitiveType name Text a UnquotedIdent Text a -> forall {a}. (Eq a, IsString a, Semigroup a) => a -> Either a PrimitiveType name Text a name :: a -> Either a PrimitiveType name = \case a "bool" -> forall a b. b -> Either a b Right PrimitiveType BoolPrimitiveType a "int2" -> forall a b. b -> Either a b Right PrimitiveType Int2PrimitiveType a "int4" -> forall a b. b -> Either a b Right PrimitiveType Int4PrimitiveType a "int8" -> forall a b. b -> Either a b Right PrimitiveType Int8PrimitiveType a "float4" -> forall a b. b -> Either a b Right PrimitiveType Float4PrimitiveType a "float8" -> forall a b. b -> Either a b Right PrimitiveType Float8PrimitiveType a "numeric" -> forall a b. b -> Either a b Right PrimitiveType NumericPrimitiveType a "char" -> forall a b. b -> Either a b Right PrimitiveType CharPrimitiveType a "text" -> forall a b. b -> Either a b Right PrimitiveType TextPrimitiveType a "bytea" -> forall a b. b -> Either a b Right PrimitiveType ByteaPrimitiveType a "date" -> forall a b. b -> Either a b Right PrimitiveType DatePrimitiveType a "timestamp" -> forall a b. b -> Either a b Right PrimitiveType TimestampPrimitiveType a "timestamptz" -> forall a b. b -> Either a b Right PrimitiveType TimestamptzPrimitiveType a "time" -> forall a b. b -> Either a b Right PrimitiveType TimePrimitiveType a "timetz" -> forall a b. b -> Either a b Right PrimitiveType TimetzPrimitiveType a "interval" -> forall a b. b -> Either a b Right PrimitiveType IntervalPrimitiveType a "uuid" -> forall a b. b -> Either a b Right PrimitiveType UuidPrimitiveType a "inet" -> forall a b. b -> Either a b Right PrimitiveType InetPrimitiveType a "json" -> forall a b. b -> Either a b Right PrimitiveType JsonPrimitiveType a "jsonb" -> forall a b. b -> Either a b Right PrimitiveType JsonbPrimitiveType a name -> forall a b. a -> Either a b Left (a "No codec exists for type: " forall a. Semigroup a => a -> a -> a <> a name)