unison-sqlite-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Sqlite.Connection

Synopsis

Connection management

data Connection Source #

A non-thread safe connection to a SQLite database.

Constructors

Connection 

Fields

Instances

Instances details
Show Connection Source # 
Instance details

Defined in Unison.Sqlite.Connection.Internal

withConnection Source #

Arguments

:: 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

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 #

queryOneCol :: forall a. (FromField a, HasCallStack) => Connection -> Sql -> IO a Source #

With checks

queryListColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> ([a] -> Either e r) -> IO r Source #

queryMaybeColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO (Maybe r) Source #

queryOneColCheck :: forall a e r. (FromField a, SqliteExceptionReason e, HasCallStack) => Connection -> Sql -> (a -> Either e r) -> IO r Source #

Rows modified

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 #

savepoint :: Connection -> Text -> IO () Source #

SAVEPOINT

rollbackTo :: Connection -> Text -> IO () Source #

ROLLBACK TO

release :: Connection -> Text -> IO () Source #

RELEASE

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.

Constructors

ExpectedAtMostOneRowException 

Fields

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.