Safe Haskell | None |
---|---|
Language | Haskell2010 |
API for building Selda backends and adding support for more types in queries.
- class MonadIO m => MonadSelda m where
- data SeldaT m a
- type SeldaM = SeldaT IO
- data SeldaError
- data StmtID
- data BackendID
- = SQLite
- | PostgreSQL
- | Other Text
- type QueryRunner a = Text -> [Param] -> IO a
- data SeldaBackend = SeldaBackend {
- runStmt :: Text -> [Param] -> IO (Int, [[SqlValue]])
- runStmtWithPK :: Text -> [Param] -> IO Int
- prepareStmt :: StmtID -> [SqlTypeRep] -> Text -> IO Dynamic
- runPrepared :: Dynamic -> [Param] -> IO (Int, [[SqlValue]])
- ppConfig :: PPConfig
- closeConnection :: SeldaConnection -> IO ()
- backendId :: BackendID
- data SeldaConnection
- class Typeable a => SqlType a where
- data SqlValue where
- data SqlTypeRep
- data Param 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 ColAttr
- data PPConfig = PPConfig {
- ppType :: SqlTypeRep -> Text
- ppTypeHook :: SqlTypeRep -> [ColAttr] -> (SqlTypeRep -> Text) -> Text
- ppTypePK :: SqlTypeRep -> Text
- ppPlaceholder :: Int -> Text
- ppColAttrs :: [ColAttr] -> Text
- ppColAttrsHook :: SqlTypeRep -> [ColAttr] -> ([ColAttr] -> Text) -> Text
- ppAutoIncInsert :: Text
- ppMaxInsertParams :: Maybe Int
- defPPConfig :: PPConfig
- newConnection :: MonadIO m => SeldaBackend -> Text -> m SeldaConnection
- allStmts :: SeldaConnection -> IO [(StmtID, Dynamic)]
- seldaBackend :: MonadSelda m => m SeldaBackend
- runSeldaT :: (MonadIO m, MonadMask m) => SeldaT m a -> SeldaConnection -> m a
- seldaClose :: MonadIO m => SeldaConnection -> m ()
- sqlDateTimeFormat :: String
- sqlDateFormat :: String
- sqlTimeFormat :: String
Documentation
class MonadIO m => MonadSelda m where Source #
Some monad with Selda SQL capabilitites.
seldaConnection :: m SeldaConnection Source #
Get the connection in use by the computation.
invalidateTable :: Table a -> m () Source #
Invalidate the given table as soon as the current transaction finishes. Invalidate the table immediately if no transaction is ongoing.
:: m () | Signal transaction commit to SQL backend. |
-> m () | Signal transaction rollback to SQL backend. |
-> m a | Transaction to perform. |
-> m a |
Safely wrap a transaction. To ensure consistency of the in-process cache, it is important that any cached tables modified during a transaction are invalidated ONLY if that transaction succeeds, AFTER the changes become visible in the database.
In order to be thread-safe in the presence of asynchronous exceptions, instances should:
- Mask async exceptions.
- Start bookkeeping of tables invalidated during the transaction.
- Perform the transaction, with async exceptions restored.
- Commit transaction, invalidate tables, and disable bookkeeping; OR
- If an exception was raised, rollback transaction and disable bookkeeping.
See the instance for SeldaT
for an example of how to do this safely.
Monad transformer adding Selda SQL capabilities.
MonadTrans SeldaT Source # | |
Monad m => Monad (SeldaT m) Source # | |
Functor m => Functor (SeldaT m) Source # | |
Monad m => Applicative (SeldaT m) Source # | |
MonadIO m => MonadIO (SeldaT m) Source # | |
MonadThrow m => MonadThrow (SeldaT m) Source # | |
MonadCatch m => MonadCatch (SeldaT m) Source # | |
MonadMask m => MonadMask (SeldaT m) Source # | |
(MonadIO m, MonadMask m) => MonadSelda (SeldaT m) Source # | |
data SeldaError Source #
Thrown by any function in SeldaT
if an error occurs.
A prepared statement identifier. Guaranteed to be unique per application.
Uniquely identifies some particular backend.
When publishing a new backend, consider submitting a pull request with a
constructor for your backend instead of using the Other
constructor.
type QueryRunner a = Text -> [Param] -> IO a Source #
A function which executes a query and gives back a list of extensible tuples; one tuple per result row, and one tuple element per column.
data SeldaBackend Source #
A collection of functions making up a Selda backend.
SeldaBackend | |
|
data SeldaConnection Source #
class Typeable a => SqlType a where Source #
Any datatype representable in (Selda's subset of) SQL.
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.
defaultValue :: Lit a Source #
Default value when using def
at this type.
SqlType Bool Source # | |
SqlType Double Source # | |
SqlType Int Source # | |
(Typeable * a, SqlEnum a) => SqlType a Source # | |
SqlType ByteString Source # | |
SqlType ByteString Source # | |
SqlType Text Source # | |
SqlType TimeOfDay Source # | |
SqlType UTCTime Source # | |
SqlType Day Source # | |
SqlType RowID Source # | |
SqlType a => SqlType (Maybe a) Source # | |
Some value that is representable in SQL.
data SqlTypeRep Source #
Representation of an SQL type.
A parameter to a prepared SQL statement.
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 |
Column attributes such as nullability, auto increment, etc. When adding elements, make sure that they are added in the order required by SQL syntax, as this list is only sorted before being pretty-printed.
Backend-specific configuration for the SQL pretty-printer.
PPConfig | |
|
defPPConfig :: PPConfig Source #
Default settings for pretty-printing. Geared towards SQLite.
The default definition of ppTypePK
is 'defType, so that you don’t have to do anything
special if you don’t use special types for primary keys.
newConnection :: MonadIO m => SeldaBackend -> Text -> m SeldaConnection Source #
Create a new Selda connection for the given backend and database identifier string.
allStmts :: SeldaConnection -> IO [(StmtID, Dynamic)] Source #
Get all statements and their corresponding identifiers for the current connection.
seldaBackend :: MonadSelda m => m SeldaBackend Source #
Get the backend in use by the computation.
runSeldaT :: (MonadIO m, MonadMask m) => SeldaT m a -> SeldaConnection -> m a Source #
Run a Selda transformer. Backends should use this to implement their
withX
functions.
seldaClose :: MonadIO m => SeldaConnection -> m () Source #
Close a reusable Selda connection.
Closing a connection while in use is undefined.
Passing a closed connection to runSeldaT
results in a SeldaError
being thrown. Closing a connection more than once is a no-op.
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.