persistent-sqlite-2.13.1.1: Backend for the persistent library using sqlite3.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Database.Sqlite

Description

A port of the direct-sqlite package for dealing directly with PersistValues.

Synopsis

Documentation

data Connection Source #

SQLite connection type, consist of an IORef tracking whether the connection has been closed and the raw SQLite C API pointer, wrapped in a 'Connection'' newtype.

Since: 2.10.2

data Statement Source #

Newtype wrapping SQLite C API pointer for a prepared statement.

Since: 2.10.2

data SqliteException Source #

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

Since: 2.1.3

Constructors

SqliteException 

data StepResult Source #

Constructors

Row 
Done 

Instances

Instances details
Show StepResult Source # 
Instance details

Defined in Database.Sqlite

Eq StepResult Source # 
Instance details

Defined in Database.Sqlite

data Config Source #

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 Source #

Since: 2.1.4

data SqliteStatus Source #

Return type of the status function

Since: 2.6.1

Constructors

SqliteStatus 

Fields

Instances

Instances details
Show SqliteStatus Source # 
Instance details

Defined in Database.Sqlite

Eq SqliteStatus Source # 
Instance details

Defined in Database.Sqlite

data SqliteStatusVerb Source #

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.

Basic usage guide

Note that the example code shown here is a low level interface usage. Let's create a small demo sqlite3 database which we will use in our program:

$ sqlite3 ~/test.db
sqlite> create table t1(a,b);
sqlite> insert into t1(a,b) values (1,1);
sqlite> insert into t1(a,b) values (2,2);
sqlite> select * from t1;
1|1
2|2

Now let's write code using the functions in this module to fetch the rows from the table:

{-#LANGUAGE OverloadedStrings#-}

import Database.Sqlite
import Data.Text

main :: IO ()
main = do
  conn <- open "/home/sibi/test.db"
  smt <- prepare conn "select * from t1;"
  row1 <- step smt >> columns smt
  row2 <- step smt >> columns smt
  print (row1, row2)
  finalize smt
  close conn

On executing the above code:

$ ./demo-program
$ ([PersistInt64 1,PersistInt64 1],[PersistInt64 2,PersistInt64 2])

step :: Statement -> IO StepResult Source #

Execute a database statement. It's recommended to use stepConn instead, because it gives better error messages.

stepConn :: Connection -> Statement -> IO StepResult Source #

Execute a database statement. This function uses the Connection passed to it to give better error messages than step.

Since: 2.6.4

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

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

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 () Source #

Releases a native FunPtr for the LogFunction.

Since: 2.1.4

config :: Config -> IO () Source #

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 Source #

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 Source #

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