Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Connection = Connection {}
- withConnection :: MonadUnliftIO m => String -> FilePath -> (Connection -> m a) -> m a
- execute :: HasCallStack => Connection -> Sql -> IO ()
- executeStatements :: HasCallStack => Connection -> Text -> IO ()
- queryStreamRow :: (HasCallStack, FromRow a) => Connection -> Sql -> (IO (Maybe a) -> IO r) -> IO r
- queryStreamCol :: forall a r. (HasCallStack, FromField a) => Connection -> Sql -> (IO (Maybe a) -> IO r) -> IO r
- queryListRow :: forall a. (FromRow a, HasCallStack) => Connection -> Sql -> IO [a]
- queryListCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO [a]
- queryMaybeRow :: (FromRow a, HasCallStack) => Connection -> Sql -> IO (Maybe a)
- queryMaybeCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO (Maybe a)
- queryOneRow :: (FromRow a, HasCallStack) => Connection -> Sql -> IO a
- queryOneCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO a
- queryListRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> ([a] -> Either e r) -> IO r
- queryListColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> ([a] -> Either e r) -> IO r
- queryMaybeRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO (Maybe r)
- queryMaybeColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO (Maybe r)
- queryOneRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO r
- queryOneColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO r
- rowsModified :: Connection -> IO Int
- vacuum :: Connection -> IO Bool
- vacuumInto :: Connection -> FilePath -> IO ()
- begin :: Connection -> IO ()
- beginImmediate :: Connection -> IO ()
- commit :: Connection -> IO ()
- rollback :: Connection -> IO ()
- withSavepoint :: MonadUnliftIO m => Connection -> Text -> (m () -> m a) -> m a
- withSavepointIO :: Connection -> Text -> (IO () -> IO a) -> IO a
- savepoint :: Connection -> Text -> IO ()
- rollbackTo :: Connection -> Text -> IO ()
- release :: Connection -> Text -> IO ()
- newtype ExpectedAtMostOneRowException = ExpectedAtMostOneRowException {}
- newtype ExpectedExactlyOneRowException = ExpectedExactlyOneRowException {}
Connection management
data Connection Source #
A non-thread safe connection to a SQLite database.
Instances
Show Connection Source # | |
Defined in Unison.Sqlite.Connection.Internal showsPrec :: Int -> Connection -> ShowS # show :: Connection -> String # showList :: [Connection] -> ShowS # |
:: MonadUnliftIO m | |
=> String | Connection name, for debugging. |
-> FilePath | Path to SQLite database file. |
-> (Connection -> m a) | |
-> m a |
Perform an action with a connection to a SQLite database.
Note: the connection is created with PRAGMA foreign_keys = ON
automatically, to work around the fact that SQLite
does not automatically enforce foreign key integrity, because it elected to maintain backwards compatibility with
code that was written before the foreign key integrity feature was implemented.
Executing queries
Without results
execute :: HasCallStack => Connection -> Sql -> IO () Source #
executeStatements :: HasCallStack => Connection -> Text -> IO () Source #
Execute one or more semicolon-delimited statements.
This function does not support parameters, and is mostly useful for executing DDL and migrations.
With results
queryStreamRow :: (HasCallStack, FromRow a) => Connection -> Sql -> (IO (Maybe a) -> IO r) -> IO r Source #
queryStreamCol :: forall a r. (HasCallStack, FromField a) => Connection -> Sql -> (IO (Maybe a) -> IO r) -> IO r Source #
queryListRow :: forall a. (FromRow a, HasCallStack) => Connection -> Sql -> IO [a] Source #
queryListCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO [a] Source #
queryMaybeRow :: (FromRow a, HasCallStack) => Connection -> Sql -> IO (Maybe a) Source #
queryMaybeCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO (Maybe a) Source #
queryOneRow :: (FromRow a, HasCallStack) => Connection -> Sql -> IO a Source #
queryOneCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO a Source #
With checks
queryListRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> ([a] -> Either e r) -> IO r Source #
queryListColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> ([a] -> Either e r) -> IO r Source #
queryMaybeRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO (Maybe r) Source #
queryMaybeColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO (Maybe r) Source #
queryOneRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO r Source #
queryOneColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO r Source #
Rows modified
rowsModified :: Connection -> IO Int Source #
Vacuum (into)
vacuum :: Connection -> IO Bool Source #
VACUUM
, and return whether or not the vacuum succeeded. A vacuum fails if the connection has any open
transactions.
vacuumInto :: Connection -> FilePath -> IO () Source #
VACUUM INTO
Low-level operations
Transaction
begin :: Connection -> IO () Source #
BEGIN
beginImmediate :: Connection -> IO () Source #
BEGIN IMMEDIATE
commit :: Connection -> IO () Source #
COMMIT
rollback :: Connection -> IO () Source #
ROLLBACK
Savepoint
withSavepoint :: MonadUnliftIO m => Connection -> Text -> (m () -> m a) -> m a Source #
Perform an action within a named savepoint. The action is provided a rollback action.
withSavepointIO :: Connection -> Text -> (IO () -> IO a) -> IO a Source #
rollbackTo :: Connection -> Text -> IO () Source #
ROLLBACK TO
Exceptions
newtype ExpectedAtMostOneRowException Source #
A query was expected to return exactly one row, but it did not. The exception carries a string representation of the rows that were actually returned.
Instances
newtype ExpectedExactlyOneRowException Source #
A query was expected to return exactly one row, but it did not. The exception carries a string representation of the rows that were actually returned.