Database.Sqlite

persistent-sqlite-2.6.2: Backend for the persistent library using sqlite3.

Safe Haskell | None
Language | Haskell98

Database.Sqlite

Description

A port of the direct-sqlite package for dealing directly with `PersistValue`s.

Synopsis

- data Connection
- data Statement
- data Error
  - = ErrorOK
  - | ErrorError
  - | ErrorInternal
  - | ErrorPermission
  - | ErrorAbort
  - | ErrorBusy
  - | ErrorLocked
  - | ErrorNoMemory
  - | ErrorReadOnly
  - | ErrorInterrupt
  - | ErrorIO
  - | ErrorNotFound
  - | ErrorCorrupt
  - | ErrorFull
  - | ErrorCan'tOpen
  - | ErrorProtocol
  - | ErrorEmpty
  - | ErrorSchema
  - | ErrorTooBig
  - | ErrorConstraint
  - | ErrorMismatch
  - | ErrorMisuse
  - | ErrorNoLargeFileSupport
  - | ErrorAuthorization
  - | ErrorFormat
  - | ErrorRange
  - | ErrorNotAConnection
  - | ErrorRow
  - | ErrorDone
- data SqliteException = SqliteException {
  - seError :: !Error
  - seFunctionName :: !Text
  - seDetails :: !Text
  }
- data StepResult
  - = Row
  - | Done
- data Config = ConfigLogFn LogFunction
- data LogFunction
- data SqliteStatus = SqliteStatus {
  - sqliteStatusCurrent :: Maybe Int
  - sqliteStatusHighwater :: Maybe Int
  }
- data SqliteStatusVerb
  - = SqliteStatusMemoryUsed
  - | SqliteStatusPagecacheUsed
  - | SqliteStatusPagecacheOverflow
  - | SqliteStatusScratchUsed
  - | SqliteStatusScratchOverflow
  - | SqliteStatusMallocSize
  - | SqliteStatusPagecacheSize
  - | SqliteStatusScratchSize
  - | SqliteStatusMallocCount
- open :: Text -> IO Connection
- close :: Connection -> IO ()
- prepare :: Connection -> Text -> IO Statement
- step :: Statement -> IO StepResult
- reset :: Connection -> Statement -> IO ()
- finalize :: Statement -> IO ()
- bindBlob :: Statement -> Int -> ByteString -> IO ()
- bindDouble :: Statement -> Int -> Double -> IO ()
- bindInt :: Statement -> Int -> Int -> IO ()
- bindInt64 :: Statement -> Int -> Int64 -> IO ()
- bindNull :: Statement -> Int -> IO ()
- bindText :: Statement -> Int -> Text -> IO ()
- bind :: Statement -> [PersistValue] -> IO ()
- column :: Statement -> Int -> IO PersistValue
- columns :: Statement -> IO [PersistValue]
- changes :: Connection -> IO Int64
- mkLogFunction :: (Int -> String -> IO ()) -> IO LogFunction
- freeLogFunction :: LogFunction -> IO ()
- config :: Config -> IO ()
- status :: SqliteStatusVerb -> Bool -> IO SqliteStatus
- softHeapLimit :: Int64 -> IO Int64

# Documentation

data Connection #

data Statement #

data Error #

Constructors

ErrorOK |
ErrorError |
ErrorInternal |
ErrorPermission |
ErrorAbort |
ErrorBusy |
ErrorLocked |
ErrorNoMemory |
ErrorReadOnly |
ErrorInterrupt |
ErrorIO |
ErrorNotFound |
ErrorCorrupt |
ErrorFull |
ErrorCan'tOpen |
ErrorProtocol |
ErrorEmpty |
ErrorSchema |
ErrorTooBig |
ErrorConstraint |
ErrorMismatch |
ErrorMisuse |
ErrorNoLargeFileSupport |
ErrorAuthorization |
ErrorFormat |
ErrorRange |
ErrorNotAConnection |
ErrorRow |
ErrorDone |

Instances

Eq Error # |
Methods (==) :: Error -> Error -> Bool # (/=) :: Error -> Error -> Bool #
Show Error # |
Methods showsPrec :: Int -> Error -> ShowS # show :: Error -> String # showList :: [Error] -> ShowS #

data SqliteException #

A custom exception type to make it easier to catch exceptions.

Since 2.1.3

Constructors

SqliteException |
Fields seError :: !Error seFunctionName :: !Text seDetails :: !Text

Instances

Show SqliteException # |
Methods showsPrec :: Int -> SqliteException -> ShowS # show :: SqliteException -> String # showList :: [SqliteException] -> ShowS #
Exception SqliteException # |
Methods toException :: SqliteException -> SomeException # fromException :: SomeException -> Maybe SqliteException # displayException :: SqliteException -> String #

data StepResult #

Constructors

Row |
Done |

Instances

Eq StepResult # |
Methods (==) :: StepResult -> StepResult -> Bool # (/=) :: StepResult -> StepResult -> Bool #
Show StepResult # |
Methods showsPrec :: Int -> StepResult -> ShowS # show :: StepResult -> String # showList :: [StepResult] -> ShowS #

data Config #

Configuration option for SQLite to be used together with the `config` function.

Since 2.1.4

Constructors

ConfigLogFn LogFunction | A function to be used for logging

data LogFunction #

Since 2.1.4

data SqliteStatus #

Return type of the `status` function

Since 2.6.1

Constructors

SqliteStatus |
Fields sqliteStatusCurrent :: Maybe Int The current value of the parameter. Some parameters do not record current value. sqliteStatusHighwater :: Maybe Int The highest recorded value. Some parameters do not record the highest value.

Instances

Eq SqliteStatus # |
Methods (==) :: SqliteStatus -> SqliteStatus -> Bool # (/=) :: SqliteStatus -> SqliteStatus -> Bool #
Show SqliteStatus # |
Methods showsPrec :: Int -> SqliteStatus -> ShowS # show :: SqliteStatus -> String # showList :: [SqliteStatus] -> ShowS #

data SqliteStatusVerb #

Run-time status parameter that can be returned by `status` function.

Since 2.6.1

Constructors

SqliteStatusMemoryUsed | This parameter is the current amount of memory checked out using sqlite3_malloc(), either directly or indirectly. The figure includes calls made to sqlite3_malloc() by the application and internal memory usage by the SQLite library. Scratch memory controlled by SQLITE_CONFIG_SCRATCH and auxiliary page-cache memory controlled by SQLITE_CONFIG_PAGECACHE is not included in this parameter. The amount returned is the sum of the allocation sizes as reported by the xSize method in sqlite3_mem_methods.
SqliteStatusPagecacheUsed | This parameter returns the number of pages used out of the pagecache memory allocator that was configured using SQLITE_CONFIG_PAGECACHE. The value returned is in pages, not in bytes.
SqliteStatusPagecacheOverflow | This parameter returns the number of bytes of page cache allocation which could not be satisfied by the SQLITE_CONFIG_PAGECACHE buffer and where forced to overflow to sqlite3_malloc(). The returned value includes allocations that overflowed because they where too large (they were larger than the "sz" parameter to SQLITE_CONFIG_PAGECACHE) and allocations that overflowed because no space was left in the page cache.
SqliteStatusScratchUsed | This parameter returns the number of allocations used out of the scratch memory allocator configured using SQLITE_CONFIG_SCRATCH. The value returned is in allocations, not in bytes. Since a single thread may only have one scratch allocation outstanding at time, this parameter also reports the number of threads using scratch memory at the same time.
SqliteStatusScratchOverflow | This parameter returns the number of bytes of scratch memory allocation which could not be satisfied by the SQLITE_CONFIG_SCRATCH buffer and where forced to overflow to sqlite3_malloc(). The values returned include overflows because the requested allocation was too larger (that is, because the requested allocation was larger than the "sz" parameter to SQLITE_CONFIG_SCRATCH) and because no scratch buffer slots were available.
SqliteStatusMallocSize | This parameter records the largest memory allocation request handed to sqlite3_malloc() or sqlite3_realloc() (or their internal equivalents). Only the value returned in `sqliteStatusHighwater` field of `SqliteStatus` record is of interest. The value written into the `sqliteStatusCurrent` field is Nothing.
SqliteStatusPagecacheSize | This parameter records the largest memory allocation request handed to pagecache memory allocator. Only the value returned in the `sqliteStatusHighwater` field of `SqliteStatus` record is of interest. The value written into the `sqliteStatusCurrent` field is Nothing.
SqliteStatusScratchSize | This parameter records the largest memory allocation request handed to scratch memory allocator. Only the value returned in the `sqliteStatusHighwater` field of `SqliteStatus` record is of interest. The value written into the `sqliteStatusCurrent` field is Nothing.
SqliteStatusMallocCount | This parameter records the number of separate memory allocations currently checked out.

open :: Text -> IO Connection #

close :: Connection -> IO () #

prepare :: Connection -> Text -> IO Statement #

step :: Statement -> IO StepResult #

reset :: Connection -> Statement -> IO () #

finalize :: Statement -> IO () #

bindBlob :: Statement -> Int -> ByteString -> IO () #

bindDouble :: Statement -> Int -> Double -> IO () #

bindInt :: Statement -> Int -> Int -> IO () #

bindInt64 :: Statement -> Int -> Int64 -> IO () #

bindNull :: Statement -> Int -> IO () #

bindText :: Statement -> Int -> Text -> IO () #

bind :: Statement -> [PersistValue] -> IO () #

column :: Statement -> Int -> IO PersistValue #

columns :: Statement -> IO [PersistValue] #

changes :: Connection -> IO Int64 #

mkLogFunction :: (Int -> String -> IO ()) -> IO LogFunction #

Wraps a given function to a `LogFunction` to be further used with `ConfigLogFn`. First argument of given function will take error code, second - log message. Returned value should be released with `freeLogFunction` when no longer required.

freeLogFunction :: LogFunction -> IO () #

Releases a native FunPtr for the `LogFunction`.

Since 2.1.4

config :: Config -> IO () #

Sets SQLite global configuration parameter. See SQLite documentation for the sqlite3_config function. In short, this must be called prior to any other SQLite function if you want the call to succeed.

Since 2.1.4

status :: SqliteStatusVerb -> Bool -> IO SqliteStatus #

Retrieves runtime status information about the performance of SQLite, and optionally resets various highwater marks. The first argument is a status parameter to measure, the second is reset flag. If reset flag is True then the highest recorded value is reset after being returned from this function.

Since 2.6.1

softHeapLimit :: Int64 -> IO Int64 #

Sets and/or queries the soft limit on the amount of heap memory that may be allocated by SQLite. If the argument is zero then the soft heap limit is disabled. If the argument is negative then no change is made to the soft heap limit. Hence, the current size of the soft heap limit can be determined by invoking this function with a negative argument.

Since 2.6.1