Safe Haskell | None |
---|---|
Language | Haskell2010 |
Types representable as columns in Selda's subset of SQL.
Synopsis
- class Typeable a => SqlType a where
- mkLit :: a -> Lit a
- sqlType :: Proxy a -> SqlTypeRep
- fromSql :: SqlValue -> a
- defaultValue :: Lit a
- class (Typeable a, Bounded a, Enum a) => SqlEnum a where
- data Lit a where
- LText :: !Text -> Lit Text
- LInt :: !Int -> Lit Int
- LDouble :: !Double -> Lit Double
- LBool :: !Bool -> Lit Bool
- LDateTime :: !UTCTime -> Lit UTCTime
- LDate :: !Day -> Lit Day
- LTime :: !TimeOfDay -> Lit TimeOfDay
- LJust :: SqlType a => !(Lit a) -> Lit (Maybe a)
- LBlob :: !ByteString -> Lit ByteString
- LNull :: SqlType a => Lit (Maybe a)
- LCustom :: SqlTypeRep -> Lit a -> Lit b
- LUUID :: !UUID -> Lit UUID
- data UUID
- data RowID
- data ID a
- data SqlValue where
- data SqlTypeRep
- invalidRowId :: RowID
- isInvalidRowId :: RowID -> Bool
- toRowId :: Int -> RowID
- fromRowId :: RowID -> Int
- fromId :: ID a -> Int
- toId :: Int -> ID a
- invalidId :: ID a
- isInvalidId :: ID a -> Bool
- untyped :: ID a -> RowID
- compLit :: Lit a -> Lit b -> Ordering
- litType :: Lit a -> SqlTypeRep
- sqlDateTimeFormat :: String
- sqlDateFormat :: String
- sqlTimeFormat :: String
Documentation
class Typeable a => SqlType a where Source #
Any datatype representable in (Selda's subset of) SQL.
Nothing
Create a literal of this type.
mkLit :: (Typeable a, SqlEnum a) => a -> Lit a Source #
Create a literal of this type.
sqlType :: Proxy a -> SqlTypeRep Source #
The SQL representation for this type.
fromSql :: SqlValue -> a Source #
Convert an SqlValue into this type.
fromSql :: (Typeable a, SqlEnum a) => SqlValue -> a Source #
Convert an SqlValue into this type.
defaultValue :: Lit a Source #
Default value when using def
at this type.
defaultValue :: (Typeable a, SqlEnum a) => Lit a Source #
Default value when using def
at this type.
Instances
SqlType Bool Source # | |
SqlType Double Source # | |
SqlType Int Source # | |
SqlType Ordering Source # | |
SqlType ByteString Source # | |
Defined in Database.Selda.SqlType mkLit :: ByteString -> Lit ByteString Source # sqlType :: Proxy ByteString -> SqlTypeRep Source # fromSql :: SqlValue -> ByteString Source # | |
SqlType ByteString Source # | |
Defined in Database.Selda.SqlType mkLit :: ByteString -> Lit ByteString Source # sqlType :: Proxy ByteString -> SqlTypeRep Source # fromSql :: SqlValue -> ByteString Source # | |
SqlType Text Source # | |
SqlType TimeOfDay Source # | |
SqlType UTCTime Source # | |
SqlType Day Source # | |
SqlType UUID Source # |
|
SqlType RowID Source # | |
SqlType a => SqlType (Maybe a) Source # | |
Typeable a => SqlType (ID a) Source # | |
((TypeError (((Text "'Only " :<>: ShowType a) :<>: Text "' is not a proper SQL type.") :$$: Text "Use 'the' to access the value of the column.") :: Constraint), Typeable a) => SqlType (Only a) Source # | |
class (Typeable a, Bounded a, Enum a) => SqlEnum a where Source #
Any type that's bounded, enumerable and has a text representation, and thus representable as a Selda enumerable.
While it would be more efficient to store enumerables as integers, this makes hand-rolled SQL touching the values inscrutable, and will break if the user a) derives Enum and b) changes the order of their constructors. Long-term, this should be implemented in PostgreSQL as a proper enum anyway, which mostly renders the performance argument moot.
An SQL literal.
LText :: !Text -> Lit Text | |
LInt :: !Int -> Lit Int | |
LDouble :: !Double -> Lit Double | |
LBool :: !Bool -> Lit Bool | |
LDateTime :: !UTCTime -> Lit UTCTime | |
LDate :: !Day -> Lit Day | |
LTime :: !TimeOfDay -> Lit TimeOfDay | |
LJust :: SqlType a => !(Lit a) -> Lit (Maybe a) | |
LBlob :: !ByteString -> Lit ByteString | |
LNull :: SqlType a => Lit (Maybe a) | |
LCustom :: SqlTypeRep -> Lit a -> Lit b | |
LUUID :: !UUID -> Lit UUID |
The UUID type. A Random
instance is provided which produces
version 4 UUIDs as specified in RFC 4122. The Storable
and
Binary
instances are compatible with RFC 4122, storing the fields
in network order as 16 bytes.
Instances
Eq UUID | |
Data UUID | |
Defined in Data.UUID.Types.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UUID -> c UUID # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UUID # dataTypeOf :: UUID -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c UUID) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UUID) # gmapT :: (forall b. Data b => b -> b) -> UUID -> UUID # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UUID -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UUID -> r # gmapQ :: (forall d. Data d => d -> u) -> UUID -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> UUID -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> UUID -> m UUID # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UUID -> m UUID # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UUID -> m UUID # | |
Ord UUID | |
Read UUID | |
Show UUID | |
Storable UUID | |
Defined in Data.UUID.Types.Internal | |
Binary UUID | |
NFData UUID | |
Defined in Data.UUID.Types.Internal | |
Hashable UUID | |
Defined in Data.UUID.Types.Internal | |
Random UUID | |
SqlType UUID Source # |
|
A row identifier for some table. This is the type of auto-incrementing primary keys.
A typed row identifier.
Generic tables should use this instead of RowID
.
Use untyped
to erase the type of a row identifier, and cast
from the
Database.Selda.Unsafe module if you for some reason need to add a type
to a row identifier.
Some value that is representable in SQL.
data SqlTypeRep Source #
Representation of an SQL type.
Instances
Eq SqlTypeRep Source # | |
Defined in Database.Selda.SqlType (==) :: SqlTypeRep -> SqlTypeRep -> Bool # (/=) :: SqlTypeRep -> SqlTypeRep -> Bool # | |
Ord SqlTypeRep Source # | |
Defined in Database.Selda.SqlType compare :: SqlTypeRep -> SqlTypeRep -> Ordering # (<) :: SqlTypeRep -> SqlTypeRep -> Bool # (<=) :: SqlTypeRep -> SqlTypeRep -> Bool # (>) :: SqlTypeRep -> SqlTypeRep -> Bool # (>=) :: SqlTypeRep -> SqlTypeRep -> Bool # max :: SqlTypeRep -> SqlTypeRep -> SqlTypeRep # min :: SqlTypeRep -> SqlTypeRep -> SqlTypeRep # | |
Show SqlTypeRep Source # | |
Defined in Database.Selda.SqlType showsPrec :: Int -> SqlTypeRep -> ShowS # show :: SqlTypeRep -> String # showList :: [SqlTypeRep] -> ShowS # |
invalidRowId :: RowID Source #
A row identifier which is guaranteed to not match any row in any table.
isInvalidRowId :: RowID -> Bool Source #
Is the given row identifier invalid? I.e. is it guaranteed to not match any row in any table?
toRowId :: Int -> RowID Source #
Create a row identifier from an integer. Use with caution, preferably only when reading user input.
fromId :: ID a -> Int Source #
Create a typed row identifier from an integer. Use with caution, preferably only when reading user input.
Create a typed row identifier from an integer. Use with caution, preferably only when reading user input.
A typed row identifier which is guaranteed to not match any row in any table.
isInvalidId :: ID a -> Bool Source #
Is the given typed row identifier invalid? I.e. is it guaranteed to not match any row in any table?
litType :: Lit a -> SqlTypeRep Source #
The SQL type representation for the given literal.
sqlDateTimeFormat :: String Source #
Format string used to represent date and time when
representing timestamps as text.
If at all possible, use SqlUTCTime
instead.
sqlDateFormat :: String Source #
Format string used to represent date when
representing dates as text.
If at all possible, use SqlDate
instead.
sqlTimeFormat :: String Source #
Format string used to represent time of day when
representing time as text.
If at all possible, use SqlTime
instead.