{-# LANGUAGE UndecidableInstances #-}
module Database.Beam.Query.DataTypes where
import Database.Beam.Backend.SQL
import Database.Beam.Query.Internal
import Data.Text (Text)
import Data.Time (LocalTime, Day, TimeOfDay)
import Data.Scientific (Scientific)
import Data.Typeable (Typeable)
import Data.Vector (Vector)
newtype DataType be a = DataType (BeamSqlBackendCastTargetSyntax be)
instance Sql92DisplaySyntax (BeamSqlBackendCastTargetSyntax be) => Show (DataType be a) where
show (DataType syntax) = "DataType (" ++ displaySyntax syntax ++ ")"
deriving instance Eq (BeamSqlBackendCastTargetSyntax be) => Eq (DataType be a)
cast_ :: BeamSqlBackend be => QGenExpr ctxt be s a -> DataType be b -> QGenExpr ctxt be s b
cast_ (QExpr e) (DataType dt) = QExpr (castE <$> e <*> pure dt)
int :: (BeamSqlBackend be, Integral a) => DataType be a
int = DataType intType
smallint :: (BeamSqlBackend be, Integral a) => DataType be a
smallint = DataType smallIntType
bigint :: ( BeamSqlBackend be, BeamSqlT071Backend be, Integral a )
=> DataType be a
bigint = DataType bigIntType
binary :: ( BeamSqlBackend be, BeamSqlT021Backend be )
=> Maybe Word -> DataType be Integer
binary prec = DataType (binaryType prec)
varbinary :: ( BeamSqlBackend be, BeamSqlT021Backend be )
=> Maybe Word -> DataType be Integer
varbinary prec = DataType (varBinaryType prec)
date :: BeamSqlBackend be => DataType be Day
date = DataType dateType
char :: BeamSqlBackend be => Maybe Word -> DataType be Text
char prec = DataType (charType prec Nothing)
varchar :: BeamSqlBackend be => Maybe Word -> DataType be Text
varchar prec = DataType (varCharType prec Nothing)
nationalVarchar :: BeamSqlBackend be => Maybe Word -> DataType be Text
nationalVarchar prec = DataType (nationalVarCharType prec)
nationalChar :: BeamSqlBackend be => Maybe Word -> DataType be Text
nationalChar prec = DataType (nationalCharType prec)
double :: BeamSqlBackend be => DataType be Double
double = DataType doubleType
numeric :: BeamSqlBackend be => Maybe (Word, Maybe Word) -> DataType be Scientific
numeric x = DataType (numericType x)
timestamptz :: BeamSqlBackend be => DataType be LocalTime
timestamptz = DataType (timestampType Nothing True)
timestamp :: BeamSqlBackend be => DataType be LocalTime
timestamp = DataType (timestampType Nothing False)
time :: BeamSqlBackend be => Maybe Word -> DataType be TimeOfDay
time prec = DataType (timeType prec False)
boolean :: BeamSql99DataTypeBackend be => DataType be Bool
boolean = DataType booleanType
characterLargeObject :: BeamSql99DataTypeBackend be => DataType be Text
characterLargeObject = DataType characterLargeObjectType
binaryLargeObject :: BeamSql99DataTypeBackend be => DataType be Text
binaryLargeObject = DataType binaryLargeObjectType
array :: (Typeable a, BeamSql99DataTypeBackend be)
=> DataType be a -> Int
-> DataType be (Vector a)
array (DataType ty) sz = DataType (arrayType ty sz)
maybeType :: DataType be a -> DataType be (Maybe a)
maybeType (DataType sqlTy) = DataType sqlTy