Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Types representable as columns in Selda's subset of SQL.
Synopsis
- class Typeable a => SqlType a where
- 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 :: !Text -> Lit UTCTime
- LDate :: !Text -> Lit Day
- LTime :: !Text -> Lit TimeOfDay
- LJust :: SqlType a => !(Lit a) -> Lit (Maybe a)
- LBlob :: !ByteString -> Lit ByteString
- LNull :: SqlType a => Lit (Maybe a)
- LCustom :: Lit a -> Lit b
- 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.
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 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 :: !Text -> Lit UTCTime | |
LDate :: !Text -> Lit Day | |
LTime :: !Text -> Lit TimeOfDay | |
LJust :: SqlType a => !(Lit a) -> Lit (Maybe a) | |
LBlob :: !ByteString -> Lit ByteString | |
LNull :: SqlType a => Lit (Maybe a) | |
LCustom :: Lit a -> Lit b |
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 talking to the database backend.
sqlDateFormat :: String Source #
Format string used to represent date when talking to the database backend.
sqlTimeFormat :: String Source #
Format string used to represent time of day when talking to the database backend.