Safe Haskell | None |
---|---|
Language | Haskell98 |
Synopsis
- initialize :: String -> IO Connection
- purge :: SessionMonad m => m ()
- privateMemory :: String
- sharedMemory :: String
- query :: (ToRow q, FromRow r, SessionMonad m) => Query -> q -> m [r]
- query_ :: (FromRow r, SessionMonad m) => Query -> m [r]
- queryNamed :: (FromRow r, SessionMonad m) => Query -> [NamedParam] -> m [r]
- execute :: (ToRow q, SessionMonad m) => Query -> q -> m ()
- execute_ :: SessionMonad m => Query -> m ()
- executeMany :: (ToRow q, SessionMonad m) => Query -> [q] -> m ()
- executeNamed :: SessionMonad m => Query -> [NamedParam] -> m ()
- withTemporaryTable :: SessionMonad m => String -> [String] -> m a -> m a
- updatePackageDb :: SessionMonad m => PackageDb -> [ModulePackage] -> m ()
- removePackageDb :: SessionMonad m => PackageDb -> m ()
- insertPackageDb :: SessionMonad m => PackageDb -> [ModulePackage] -> m ()
- updateProject :: SessionMonad m => Project -> m ()
- removeProject :: SessionMonad m => Project -> m ()
- insertProject :: SessionMonad m => Project -> m ()
- insertBuildInfo :: SessionMonad m => Info -> m Int
- removeModuleContents :: SessionMonad m => Int -> m ()
- removeModule :: SessionMonad m => Int -> m ()
- lookupModuleLocation :: SessionMonad m => ModuleLocation -> m (Maybe Int)
- lookupModule :: SessionMonad m => ModuleId -> m (Maybe Int)
- lookupSymbol :: SessionMonad m => Int -> SymbolId -> m (Maybe Int)
- lastRow :: SessionMonad m => m Int
- loadModule :: SessionMonad m => Int -> m Module
- loadModules :: (SessionMonad m, ToRow q) => String -> q -> m [Module]
- loadProject :: SessionMonad m => Path -> m Project
- updateModules :: SessionMonad m => [InspectedModule] -> m ()
- upsertModules :: SessionMonad m => [InspectedModule] -> m [Int]
- lookupId :: SessionMonad m => ModuleLocation -> m Int
- escapeLike :: Text -> Text
- newtype Only a = Only {
- fromOnly :: a
- data SQLData
- = SQLInteger !Int64
- | SQLFloat !Double
- | SQLText !Text
- | SQLBlob !ByteString
- | SQLNull
- data SQLError = SQLError {
- sqlError :: !Error
- sqlErrorDetails :: Text
- sqlErrorContext :: Text
- data Error
- = ErrorOK
- | ErrorError
- | ErrorInternal
- | ErrorPermission
- | ErrorAbort
- | ErrorBusy
- | ErrorLocked
- | ErrorNoMemory
- | ErrorReadOnly
- | ErrorInterrupt
- | ErrorIO
- | ErrorCorrupt
- | ErrorNotFound
- | ErrorFull
- | ErrorCan'tOpen
- | ErrorProtocol
- | ErrorEmpty
- | ErrorSchema
- | ErrorTooBig
- | ErrorConstraint
- | ErrorMismatch
- | ErrorMisuse
- | ErrorNoLargeFileSupport
- | ErrorAuthorization
- | ErrorFormat
- | ErrorRange
- | ErrorNotADatabase
- | ErrorNotice
- | ErrorWarning
- | ErrorRow
- | ErrorDone
- totalChanges :: Connection -> IO Int
- changes :: Connection -> IO Int
- lastInsertRowId :: Connection -> IO Int64
- withExclusiveTransaction :: Connection -> IO a -> IO a
- withImmediateTransaction :: Connection -> IO a -> IO a
- nextRow :: FromRow r => Statement -> IO (Maybe r)
- foldNamed :: FromRow row => Connection -> Query -> [NamedParam] -> a -> (a -> row -> IO a) -> IO a
- fold_ :: FromRow row => Connection -> Query -> a -> (a -> row -> IO a) -> IO a
- fold :: (FromRow row, ToRow params) => Connection -> Query -> params -> a -> (a -> row -> IO a) -> IO a
- queryWith_ :: RowParser r -> Connection -> Query -> IO [r]
- queryWith :: ToRow q => RowParser r -> Connection -> Query -> q -> IO [r]
- withStatement :: Connection -> Query -> (Statement -> IO a) -> IO a
- closeStatement :: Statement -> IO ()
- openStatement :: Connection -> Query -> IO Statement
- withBind :: ToRow params => Statement -> params -> IO a -> IO a
- columnCount :: Statement -> IO ColumnIndex
- columnName :: Statement -> ColumnIndex -> IO Text
- reset :: Statement -> IO ()
- bindNamed :: Statement -> [NamedParam] -> IO ()
- bind :: ToRow params => Statement -> params -> IO ()
- setTrace :: Connection -> Maybe (Text -> IO ()) -> IO ()
- withConnection :: String -> (Connection -> IO a) -> IO a
- close :: Connection -> IO ()
- open :: String -> IO Connection
- newtype Statement = Statement {}
- newtype ColumnIndex = ColumnIndex ColumnIndex
- data NamedParam where
- (:=) :: forall v. ToField v => Text -> v -> NamedParam
- data FormatError = FormatError {}
- field :: FromField a => RowParser a
- class FromRow a where
- data ResultError
- = Incompatible { }
- | UnexpectedNull { }
- | ConversionFailed { }
- class ToRow a where
- newtype Query = Query {}
- data h :. t = h :. t
- newtype Connection = Connection {}
- module HsDev.Database.SQLite.Select
- module HsDev.Database.SQLite.Instances
- module HsDev.Database.SQLite.Transaction
Documentation
initialize :: String -> IO Connection Source #
Initialize database
purge :: SessionMonad m => m () Source #
privateMemory :: String Source #
Private memory for db
sharedMemory :: String Source #
Shared db in memory
queryNamed :: (FromRow r, SessionMonad m) => Query -> [NamedParam] -> m [r] Source #
execute_ :: SessionMonad m => Query -> m () Source #
executeMany :: (ToRow q, SessionMonad m) => Query -> [q] -> m () Source #
executeNamed :: SessionMonad m => Query -> [NamedParam] -> m () Source #
withTemporaryTable :: SessionMonad m => String -> [String] -> m a -> m a Source #
updatePackageDb :: SessionMonad m => PackageDb -> [ModulePackage] -> m () Source #
removePackageDb :: SessionMonad m => PackageDb -> m () Source #
insertPackageDb :: SessionMonad m => PackageDb -> [ModulePackage] -> m () Source #
updateProject :: SessionMonad m => Project -> m () Source #
removeProject :: SessionMonad m => Project -> m () Source #
insertProject :: SessionMonad m => Project -> m () Source #
insertBuildInfo :: SessionMonad m => Info -> m Int Source #
removeModuleContents :: SessionMonad m => Int -> m () Source #
removeModule :: SessionMonad m => Int -> m () Source #
lookupModuleLocation :: SessionMonad m => ModuleLocation -> m (Maybe Int) Source #
lookupModule :: SessionMonad m => ModuleId -> m (Maybe Int) Source #
lookupSymbol :: SessionMonad m => Int -> SymbolId -> m (Maybe Int) Source #
lastRow :: SessionMonad m => m Int Source #
loadModule :: SessionMonad m => Int -> m Module Source #
loadModules :: (SessionMonad m, ToRow q) => String -> q -> m [Module] Source #
loadProject :: SessionMonad m => Path -> m Project Source #
updateModules :: SessionMonad m => [InspectedModule] -> m () Source #
Update a bunch of modules
upsertModules :: SessionMonad m => [InspectedModule] -> m [Int] Source #
Utils
lookupId :: SessionMonad m => ModuleLocation -> m Int Source #
escapeLike :: Text -> Text Source #
Reexports
The 1-tuple type or single-value "collection".
This type is structurally equivalent to the
Identity
type, but its intent is more
about serving as the anonymous 1-tuple type missing from Haskell for attaching
typeclass instances.
Parameter usage example:
encodeSomething (Only
(42::Int))
Result usage example:
xs <- decodeSomething
forM_ xs $ \(Only
id) -> {- ... -}
Instances
Functor Only | |
Eq a => Eq (Only a) | |
Data a => Data (Only a) | |
Defined in Data.Tuple.Only gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Only a -> c (Only a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Only a) # toConstr :: Only a -> Constr # dataTypeOf :: Only a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Only a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a)) # gmapT :: (forall b. Data b => b -> b) -> Only a -> Only a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r # gmapQ :: (forall d. Data d => d -> u) -> Only a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Only a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) # | |
Ord a => Ord (Only a) | |
Read a => Read (Only a) | |
Show a => Show (Only a) | |
Generic (Only a) | |
NFData a => NFData (Only a) | |
Defined in Data.Tuple.Only | |
FromField a => FromRow (Only a) | |
Defined in Database.SQLite.Simple.FromRow | |
ToField a => ToRow (Only a) | |
Defined in Database.SQLite.Simple.ToRow | |
type Rep (Only a) | |
Defined in Data.Tuple.Only |
Instances
Eq SQLData | |
Show SQLData | |
FromField SQLData | |
Defined in Database.SQLite.Simple.FromField | |
ToField SQLData | |
Defined in Database.SQLite.Simple.ToField |
Exception thrown when SQLite3 reports an error.
direct-sqlite may throw other types of exceptions if you misuse the API.
SQLError | |
|
Instances
Eq SQLError | |
Show SQLError | |
Exception SQLError | |
Defined in Database.SQLite3 toException :: SQLError -> SomeException # fromException :: SomeException -> Maybe SQLError # displayException :: SQLError -> String # |
ErrorOK | Successful result |
ErrorError | SQL error or missing database |
ErrorInternal | Internal logic error in SQLite |
ErrorPermission | Access permission denied |
ErrorAbort | Callback routine requested an abort |
ErrorBusy | The database file is locked |
ErrorLocked | A table in the database is locked |
ErrorNoMemory | A |
ErrorReadOnly | Attempt to write a readonly database |
ErrorInterrupt | Operation terminated by |
ErrorIO | Some kind of disk I/O error occurred |
ErrorCorrupt | The database disk image is malformed |
ErrorNotFound | Unknown opcode in |
ErrorFull | Insertion failed because database is full |
ErrorCan'tOpen | Unable to open the database file |
ErrorProtocol | Database lock protocol error |
ErrorEmpty | Database is empty |
ErrorSchema | The database schema changed |
ErrorTooBig | String or BLOB exceeds size limit |
ErrorConstraint | Abort due to constraint violation |
ErrorMismatch | Data type mismatch |
ErrorMisuse | Library used incorrectly |
ErrorNoLargeFileSupport | Uses OS features not supported on host |
ErrorAuthorization | Authorization denied |
ErrorFormat | Auxiliary database format error |
ErrorRange | 2nd parameter to sqlite3_bind out of range |
ErrorNotADatabase | File opened that is not a database file |
ErrorNotice | Notifications from sqlite3_log() |
ErrorWarning | Warnings from sqlite3_log() |
ErrorRow |
|
ErrorDone |
|
totalChanges :: Connection -> IO Int #
http://www.sqlite.org/c3ref/total_changes.html
Return the total number of row changes caused by INSERT
, DELETE
,
or UPDATE
statements since the Database
was opened.
changes :: Connection -> IO Int #
http://www.sqlite.org/c3ref/changes.html
Return the number of rows that were changed, inserted, or deleted
by the most recent INSERT
, DELETE
, or UPDATE
statement.
lastInsertRowId :: Connection -> IO Int64 #
Returns the rowid of the most recent successful INSERT on the given database connection.
See also http://www.sqlite.org/c3ref/last_insert_rowid.html.
withExclusiveTransaction :: Connection -> IO a -> IO a #
Run an IO action inside a SQL transaction started with BEGIN EXCLUSIVE
TRANSACTION
, which immediately blocks all other database connections from
writing, and other connections from reading (exception: read_uncommitted
connections are allowed to read.) If the action throws any kind of an
exception, the transaction will be rolled back with ROLLBACK TRANSACTION
.
Otherwise the results are committed with COMMIT TRANSACTION
.
withImmediateTransaction :: Connection -> IO a -> IO a #
Run an IO action inside a SQL transaction started with BEGIN IMMEDIATE
TRANSACTION
, which immediately blocks all other database connections from
writing. The default SQLite3 BEGIN TRANSACTION
does not acquire the write
lock on BEGIN
nor on SELECT
but waits until you try to change data. If
the action throws any kind of an exception, the transaction will be rolled
back with ROLLBACK TRANSACTION
. Otherwise the results are committed with
COMMIT TRANSACTION
.
nextRow :: FromRow r => Statement -> IO (Maybe r) #
Extracts the next row from the prepared statement.
foldNamed :: FromRow row => Connection -> Query -> [NamedParam] -> a -> (a -> row -> IO a) -> IO a #
A version of fold
where the query parameters (placeholders) are
named.
fold_ :: FromRow row => Connection -> Query -> a -> (a -> row -> IO a) -> IO a #
A version of fold
which does not perform parameter substitution.
fold :: (FromRow row, ToRow params) => Connection -> Query -> params -> a -> (a -> row -> IO a) -> IO a #
Perform a SELECT
or other SQL query that is expected to return results.
Results are converted and fed into the action
callback as they are being
retrieved from the database.
This allows gives the possibility of processing results in constant space (for instance writing them to disk).
Exceptions that may be thrown:
FormatError
: the query string mismatched with given arguments.ResultError
: result conversion failed.
queryWith_ :: RowParser r -> Connection -> Query -> IO [r] #
withStatement :: Connection -> Query -> (Statement -> IO a) -> IO a #
Opens a prepared statement, executes an action using this statement, and closes the statement, even in the presence of exceptions.
closeStatement :: Statement -> IO () #
Closes a prepared statement.
openStatement :: Connection -> Query -> IO Statement #
Opens a prepared statement. A prepared statement must always be closed with
a corresponding call to closeStatement
before closing the connection. Use
nextRow
to iterate on the values returned. Once nextRow
returns
Nothing
, you need to invoke reset
before reexecuting the statement again
with nextRow
.
withBind :: ToRow params => Statement -> params -> IO a -> IO a #
Binds parameters to a prepared statement, and reset
s the statement when
the callback completes, even in the presence of exceptions.
Use withBind
to reuse prepared statements. Because it reset
s the
statement after each usage, it avoids a pitfall involving implicit
transactions. SQLite creates an implicit transaction if you don't say
BEGIN
explicitly, and does not commit it until all active statements are
finished with either reset
or closeStatement
.
columnCount :: Statement -> IO ColumnIndex #
Return number of columns in the query
columnName :: Statement -> ColumnIndex -> IO Text #
Return the name of a a particular column in the result set of a
Statement
. Throws an ArrayException
if the colum index is out
of bounds.
Resets a statement. This does not reset bound parameters, if any, but
allows the statement to be reexecuted again by invoking nextRow
.
bindNamed :: Statement -> [NamedParam] -> IO () #
Binds named parameters to a prepared statement.
setTrace :: Connection -> Maybe (Text -> IO ()) -> IO () #
http://www.sqlite.org/c3ref/profile.html
Enable/disable tracing of SQL execution. Tracing can be disabled
by setting Nothing
as the logger callback.
Warning: If the logger callback throws an exception, your whole program may crash. Enable only for debugging!
withConnection :: String -> (Connection -> IO a) -> IO a #
Opens a database connection, executes an action using this connection, and closes the connection, even in the presence of exceptions.
close :: Connection -> IO () #
Close a database connection.
open :: String -> IO Connection #
Open a database connection to a given file. Will throw an exception if it cannot connect.
Every open
must be closed with a call to close
.
If you specify ":memory:" or an empty string as the input filename, then a private, temporary in-memory database is created for the connection. This database will vanish when you close the connection.
newtype ColumnIndex #
Index of a column in a result set. Column indices start from 0.
Instances
data NamedParam where #
(:=) :: forall v. ToField v => Text -> v -> NamedParam infixr 3 |
Instances
Show NamedParam | |
Defined in Database.SQLite.Simple showsPrec :: Int -> NamedParam -> ShowS # show :: NamedParam -> String # showList :: [NamedParam] -> ShowS # |
data FormatError #
Exception thrown if a Query
was malformed.
This may occur if the number of '?
' characters in the query
string does not match the number of parameters provided.
Instances
Eq FormatError | |
Defined in Database.SQLite.Simple (==) :: FormatError -> FormatError -> Bool # (/=) :: FormatError -> FormatError -> Bool # | |
Show FormatError | |
Defined in Database.SQLite.Simple showsPrec :: Int -> FormatError -> ShowS # show :: FormatError -> String # showList :: [FormatError] -> ShowS # | |
Exception FormatError | |
Defined in Database.SQLite.Simple |
A collection type that can be converted from a sequence of fields. Instances are provided for tuples up to 10 elements and lists of any length.
Note that instances can defined outside of sqlite-simple, which is often useful. For example, here's an instance for a user-defined pair:
@data User = User { name :: String, fileQuota :: Int }
instance FromRow
User where
fromRow = User <$> field
<*> field
@
The number of calls to field
must match the number of fields returned
in a single row of the query result. Otherwise, a ConversionFailed
exception will be thrown.
Note the caveats associated with user-defined implementations of
fromRow
.
Instances
data ResultError #
Exception thrown if conversion from a SQL value to a Haskell value fails.
Incompatible | The SQL and Haskell types are not compatible. |
| |
UnexpectedNull | A SQL |
| |
ConversionFailed | The SQL value could not be parsed, or could not be represented as a valid Haskell value, or an unexpected low-level error occurred (e.g. mismatch between metadata and actual data in a row). |
|
Instances
Eq ResultError | |
Defined in Database.SQLite.Simple.FromField (==) :: ResultError -> ResultError -> Bool # (/=) :: ResultError -> ResultError -> Bool # | |
Show ResultError | |
Defined in Database.SQLite.Simple.FromField showsPrec :: Int -> ResultError -> ShowS # show :: ResultError -> String # showList :: [ResultError] -> ShowS # | |
Exception ResultError | |
Defined in Database.SQLite.Simple.FromField |
A collection type that can be turned into a list of SQLData
elements.
Instances
A query string. This type is intended to make it difficult to construct a SQL query by concatenating string fragments, as that is an extremely common way to accidentally introduce SQL injection vulnerabilities into an application.
This type is an instance of IsString
, so the easiest way to
construct a query is to enable the OverloadedStrings
language
extension and then simply write the query in double quotes.
{-# LANGUAGE OverloadedStrings #-} import Database.SQLite.Simple q :: Query q = "select ?"
The underlying type is a Text
, and literal Haskell strings that
contain Unicode characters will be correctly transformed to UTF-8.
A composite type to parse your custom data structures without having to define dummy newtype wrappers every time.
instance FromRow MyData where ...
instance FromRow MyData2 where ...
then I can do the following for free:
res <- query' c "..." forM res $ \(MyData{..} :. MyData2{..}) -> do ....
h :. t infixr 3 |
Instances
(Eq h, Eq t) => Eq (h :. t) | |
(Ord h, Ord t) => Ord (h :. t) | |
Defined in Database.SQLite.Simple.Types | |
(Read h, Read t) => Read (h :. t) | |
(Show h, Show t) => Show (h :. t) | |
(FromRow a, FromRow b) => FromRow (a :. b) | |
Defined in Database.SQLite.Simple.FromRow | |
(ToRow a, ToRow b) => ToRow (a :. b) | |
Defined in Database.SQLite.Simple.ToRow |
newtype Connection #
Connection to an open database.
You can use connectionHandle
to gain access to the underlying
http://hackage.haskell.org/package/direct-sqlite connection.
This may be useful if you need to access some direct-sqlite
functionality that's not exposed in the sqlite-simple API. This
should be a safe thing to do although mixing both APIs is
discouraged.
module HsDev.Database.SQLite.Select