selda-0.3.4.0: Multi-backend, high-level EDSL for interacting with SQL databases.

Safe HaskellSafe
LanguageHaskell2010

Database.Selda.SqlType

Description

Types representable as columns in Selda's subset of SQL.

Synopsis

Documentation

class Typeable a => SqlType a where #

Any datatype representable in (Selda's subset of) SQL.

Minimal complete definition

Nothing

Methods

mkLit :: a -> Lit a #

Create a literal of this type.

mkLit :: (Typeable a, SqlEnum a) => a -> Lit a #

Create a literal of this type.

sqlType :: Proxy a -> SqlTypeRep #

The SQL representation for this type.

fromSql :: SqlValue -> a #

Convert an SqlValue into this type.

fromSql :: (Typeable a, SqlEnum a) => SqlValue -> a #

Convert an SqlValue into this type.

defaultValue :: Lit a #

Default value when using def at this type.

defaultValue :: (Typeable a, SqlEnum a) => Lit a #

Default value when using def at this type.

Instances
SqlType Bool # 
Instance details

Defined in Database.Selda.SqlType

SqlType Double # 
Instance details

Defined in Database.Selda.SqlType

SqlType Int # 
Instance details

Defined in Database.Selda.SqlType

SqlType Ordering # 
Instance details

Defined in Database.Selda.SqlType

SqlType ByteString # 
Instance details

Defined in Database.Selda.SqlType

SqlType ByteString # 
Instance details

Defined in Database.Selda.SqlType

SqlType Text # 
Instance details

Defined in Database.Selda.SqlType

SqlType TimeOfDay # 
Instance details

Defined in Database.Selda.SqlType

SqlType UTCTime # 
Instance details

Defined in Database.Selda.SqlType

SqlType Day # 
Instance details

Defined in Database.Selda.SqlType

SqlType RowID # 
Instance details

Defined in Database.Selda.SqlType

SqlType a => SqlType (Maybe a) # 
Instance details

Defined in Database.Selda.SqlType

Typeable a => SqlType (ID a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

mkLit :: ID a -> Lit (ID a) #

sqlType :: Proxy (ID a) -> SqlTypeRep #

fromSql :: SqlValue -> ID a #

defaultValue :: Lit (ID a) #

((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) # 
Instance details

Defined in Database.Selda

Methods

mkLit :: Only a -> Lit (Only a) #

sqlType :: Proxy (Only a) -> SqlTypeRep #

fromSql :: SqlValue -> Only a #

defaultValue :: Lit (Only a) #

class (Typeable a, Bounded a, Enum a) => SqlEnum a where #

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.

Methods

toText :: a -> Text #

fromText :: Text -> a #

Instances
(Typeable a, Bounded a, Enum a, Show a, Read a) => SqlEnum a # 
Instance details

Defined in Database.Selda.SqlType

Methods

toText :: a -> Text #

fromText :: Text -> a #

data Lit a where #

An SQL literal.

Constructors

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 
Instances
Eq (Lit a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

(==) :: Lit a -> Lit a -> Bool #

(/=) :: Lit a -> Lit a -> Bool #

Ord (Lit a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

compare :: Lit a -> Lit a -> Ordering #

(<) :: Lit a -> Lit a -> Bool #

(<=) :: Lit a -> Lit a -> Bool #

(>) :: Lit a -> Lit a -> Bool #

(>=) :: Lit a -> Lit a -> Bool #

max :: Lit a -> Lit a -> Lit a #

min :: Lit a -> Lit a -> Lit a #

Show (Lit a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

showsPrec :: Int -> Lit a -> ShowS #

show :: Lit a -> String #

showList :: [Lit a] -> ShowS #

Hashable (Lit a) # 
Instance details

Defined in Database.Selda.Caching

Methods

hashWithSalt :: Int -> Lit a -> Int #

hash :: Lit a -> Int #

data RowID #

A row identifier for some table. This is the type of auto-incrementing primary keys.

Instances
Eq RowID # 
Instance details

Defined in Database.Selda.SqlType

Methods

(==) :: RowID -> RowID -> Bool #

(/=) :: RowID -> RowID -> Bool #

Ord RowID # 
Instance details

Defined in Database.Selda.SqlType

Methods

compare :: RowID -> RowID -> Ordering #

(<) :: RowID -> RowID -> Bool #

(<=) :: RowID -> RowID -> Bool #

(>) :: RowID -> RowID -> Bool #

(>=) :: RowID -> RowID -> Bool #

max :: RowID -> RowID -> RowID #

min :: RowID -> RowID -> RowID #

Show RowID # 
Instance details

Defined in Database.Selda.SqlType

Methods

showsPrec :: Int -> RowID -> ShowS #

show :: RowID -> String #

showList :: [RowID] -> ShowS #

SqlType RowID # 
Instance details

Defined in Database.Selda.SqlType

SqlOrd RowID # 
Instance details

Defined in Database.Selda

data ID a #

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.

Instances
Eq (ID a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

(==) :: ID a -> ID a -> Bool #

(/=) :: ID a -> ID a -> Bool #

Ord (ID a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

compare :: ID a -> ID a -> Ordering #

(<) :: ID a -> ID a -> Bool #

(<=) :: ID a -> ID a -> Bool #

(>) :: ID a -> ID a -> Bool #

(>=) :: ID a -> ID a -> Bool #

max :: ID a -> ID a -> ID a #

min :: ID a -> ID a -> ID a #

Show (ID a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

showsPrec :: Int -> ID a -> ShowS #

show :: ID a -> String #

showList :: [ID a] -> ShowS #

Typeable a => SqlType (ID a) # 
Instance details

Defined in Database.Selda.SqlType

Methods

mkLit :: ID a -> Lit (ID a) #

sqlType :: Proxy (ID a) -> SqlTypeRep #

fromSql :: SqlValue -> ID a #

defaultValue :: Lit (ID a) #

Typeable a => SqlOrd (ID a) # 
Instance details

Defined in Database.Selda

data SqlValue where #

Some value that is representable in SQL.

Instances
Show SqlValue # 
Instance details

Defined in Database.Selda.SqlType

invalidRowId :: RowID #

A row identifier which is guaranteed to not match any row in any table.

isInvalidRowId :: RowID -> Bool #

Is the given row identifier invalid? I.e. is it guaranteed to not match any row in any table?

toRowId :: Int -> RowID #

Create a row identifier from an integer. Use with caution, preferably only when reading user input.

fromRowId :: RowID -> Int #

Inspect a row identifier.

fromId :: ID a -> Int #

Create a typed row identifier from an integer. Use with caution, preferably only when reading user input.

toId :: Int -> ID a #

Create a typed row identifier from an integer. Use with caution, preferably only when reading user input.

invalidId :: ID a #

A typed row identifier which is guaranteed to not match any row in any table.

isInvalidId :: ID a -> Bool #

Is the given typed row identifier invalid? I.e. is it guaranteed to not match any row in any table?

untyped :: ID a -> RowID #

compLit :: Lit a -> Lit b -> Ordering #

Compare two literals of different type for equality.

litType :: Lit a -> SqlTypeRep #

The SQL type representation for the given literal.

sqlDateTimeFormat :: String #

Format string used to represent date and time when talking to the database backend.

sqlDateFormat :: String #

Format string used to represent date when talking to the database backend.

sqlTimeFormat :: String #

Format string used to represent time of day when talking to the database backend.