-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Mid-Level SQLite client library -- -- Mid-level SQLite client library, based on postgresql-simple. -- -- Main documentation (with examples): Database.SQLite.Simple -- -- You can view the project page at -- http://github.com/nurpax/sqlite-simple for more information. @package sqlite-simple @version 0.4.17.0 -- | The Ok type is a simple error handler, basically equivalent to -- Either [SomeException]. -- -- One of the primary reasons why this type was introduced is that -- Either SomeException had not been provided an instance for -- Alternative, and it would have been a bad idea to provide an -- orphaned instance for a commonly-used type and typeclass included in -- base. -- -- Extending the failure case to a list of SomeExceptions enables -- a more sensible Alternative instance definitions: -- <|> concatinates the list of exceptions when both cases -- fail, and empty is defined as 'Errors []'. Though -- <|> one could pick one of two exceptions, and throw away -- the other, and have empty provide a generic exception, this -- avoids cases where empty overrides a more informative exception -- and allows you to see all the different ways your computation has -- failed. module Database.SQLite.Simple.Ok data Ok a Errors :: [SomeException] -> Ok a Ok :: !a -> Ok a -- | a way to reify a list of exceptions into a single exception newtype ManyErrors ManyErrors :: [SomeException] -> ManyErrors instance GHC.Show.Show Database.SQLite.Simple.Ok.ManyErrors instance GHC.Base.Functor Database.SQLite.Simple.Ok.Ok instance GHC.Show.Show a => GHC.Show.Show (Database.SQLite.Simple.Ok.Ok a) instance GHC.Exception.Type.Exception Database.SQLite.Simple.Ok.ManyErrors instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.SQLite.Simple.Ok.Ok a) instance GHC.Base.Applicative Database.SQLite.Simple.Ok.Ok instance GHC.Base.Alternative Database.SQLite.Simple.Ok.Ok instance GHC.Base.MonadPlus Database.SQLite.Simple.Ok.Ok instance GHC.Base.Monad Database.SQLite.Simple.Ok.Ok instance Control.Monad.Fail.MonadFail Database.SQLite.Simple.Ok.Ok -- | Internal bits. This interface is less stable and can change at any -- time. In particular this means that while the rest of the -- sqlite-simple package endeavors to follow the package versioning -- policy, this module does not. Also, at the moment there are things in -- here that aren't particularly internal and are exported elsewhere; -- these will eventually disappear from this module. module Database.SQLite.Simple.Internal -- | 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. newtype Connection Connection :: Database -> Connection [connectionHandle] :: Connection -> Database data ColumnOutOfBounds ColumnOutOfBounds :: !Int -> ColumnOutOfBounds [errorColumnIndex] :: ColumnOutOfBounds -> !Int -- | A Field represents metadata about a particular field data Field Field :: SQLData -> {-# UNPACK #-} !Int -> Field [result] :: Field -> SQLData [column] :: Field -> {-# UNPACK #-} !Int newtype RowParseRO RowParseRO :: Int -> RowParseRO [nColumns] :: RowParseRO -> Int newtype RowParser a RP :: ReaderT RowParseRO (StateT (Int, [SQLData]) Ok) a -> RowParser a [unRP] :: RowParser a -> ReaderT RowParseRO (StateT (Int, [SQLData]) Ok) a gettypename :: SQLData -> ByteString instance GHC.Base.MonadPlus Database.SQLite.Simple.Internal.RowParser instance GHC.Base.Monad Database.SQLite.Simple.Internal.RowParser instance GHC.Base.Alternative Database.SQLite.Simple.Internal.RowParser instance GHC.Base.Applicative Database.SQLite.Simple.Internal.RowParser instance GHC.Base.Functor Database.SQLite.Simple.Internal.RowParser instance GHC.Show.Show Database.SQLite.Simple.Internal.ColumnOutOfBounds instance GHC.Classes.Eq Database.SQLite.Simple.Internal.ColumnOutOfBounds instance GHC.Exception.Type.Exception Database.SQLite.Simple.Internal.ColumnOutOfBounds -- | Adapted from Leon P Smith's code for SQLite. -- -- See http://sqlite.org/lang_datefunc.html for date formats used -- in SQLite. module Database.SQLite.Simple.Time.Implementation parseUTCTime :: Text -> Either String UTCTime parseDay :: Text -> Either String Day -- | Output YYYY-MM-DD HH:MM:SS with an optional .SSS fraction part. -- Explicit timezone attribute is not appended as per SQLite3's datetime -- conventions. utcTimeToBuilder :: UTCTime -> Builder dayToBuilder :: Day -> Builder timeOfDayToBuilder :: TimeOfDay -> Builder timeZoneToBuilder :: TimeZone -> Builder -- | Conversions to/from Haskell UTCTime and Day types -- for SQLite3. Offers better performance than direct use of time -- package's read/show functionality. -- -- The parsers are heavily adapted for the specific variant of ISO 8601 -- that SQLite uses, and the printers attempt to duplicate this syntax. module Database.SQLite.Simple.Time -- | Top-level module for sqlite-simple. module Database.SQLite.Simple.Types -- | A placeholder for the SQL NULL value. data Null Null :: Null -- | 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) -> {- ... -}
--   
newtype Only a Only :: a -> Only a [fromOnly] :: Only a -> a -- | 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. newtype Query Query :: Text -> Query [fromQuery] :: Query -> Text -- | 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
--     ....
--   
data h :. t (:.) :: h -> t -> (:.) h t infixr 3 :. infixr 3 :. instance (GHC.Read.Read h, GHC.Read.Read t) => GHC.Read.Read (h Database.SQLite.Simple.Types.:. t) instance (GHC.Show.Show h, GHC.Show.Show t) => GHC.Show.Show (h Database.SQLite.Simple.Types.:. t) instance (GHC.Classes.Ord h, GHC.Classes.Ord t) => GHC.Classes.Ord (h Database.SQLite.Simple.Types.:. t) instance (GHC.Classes.Eq h, GHC.Classes.Eq t) => GHC.Classes.Eq (h Database.SQLite.Simple.Types.:. t) instance GHC.Classes.Ord Database.SQLite.Simple.Types.Query instance GHC.Classes.Eq Database.SQLite.Simple.Types.Query instance GHC.Show.Show Database.SQLite.Simple.Types.Null instance GHC.Read.Read Database.SQLite.Simple.Types.Null instance GHC.Show.Show Database.SQLite.Simple.Types.Query instance GHC.Read.Read Database.SQLite.Simple.Types.Query instance Data.String.IsString Database.SQLite.Simple.Types.Query instance GHC.Base.Semigroup Database.SQLite.Simple.Types.Query instance GHC.Base.Monoid Database.SQLite.Simple.Types.Query instance GHC.Classes.Eq Database.SQLite.Simple.Types.Null -- | The ToField typeclass, for rendering a parameter to an SQLite -- value to be bound as a SQL query parameter. module Database.SQLite.Simple.ToField -- | A type that may be used as a single parameter to a SQL query. class ToField a -- | Prepare a value for substitution into a query string. toField :: ToField a => a -> SQLData instance Database.SQLite.Simple.ToField.ToField Database.SQLite3.SQLData instance Database.SQLite.Simple.ToField.ToField a => Database.SQLite.Simple.ToField.ToField (GHC.Maybe.Maybe a) instance Database.SQLite.Simple.ToField.ToField Database.SQLite.Simple.Types.Null instance Database.SQLite.Simple.ToField.ToField GHC.Types.Bool instance Database.SQLite.Simple.ToField.ToField GHC.Int.Int8 instance Database.SQLite.Simple.ToField.ToField GHC.Int.Int16 instance Database.SQLite.Simple.ToField.ToField GHC.Int.Int32 instance Database.SQLite.Simple.ToField.ToField GHC.Types.Int instance Database.SQLite.Simple.ToField.ToField GHC.Int.Int64 instance Database.SQLite.Simple.ToField.ToField GHC.Integer.Type.Integer instance Database.SQLite.Simple.ToField.ToField GHC.Word.Word8 instance Database.SQLite.Simple.ToField.ToField GHC.Word.Word16 instance Database.SQLite.Simple.ToField.ToField GHC.Word.Word32 instance Database.SQLite.Simple.ToField.ToField GHC.Types.Word instance Database.SQLite.Simple.ToField.ToField GHC.Word.Word64 instance Database.SQLite.Simple.ToField.ToField GHC.Types.Float instance Database.SQLite.Simple.ToField.ToField GHC.Types.Double instance Database.SQLite.Simple.ToField.ToField Data.ByteString.Internal.ByteString instance Database.SQLite.Simple.ToField.ToField Data.ByteString.Lazy.Internal.ByteString instance Database.SQLite.Simple.ToField.ToField Data.Text.Internal.Text instance Database.SQLite.Simple.ToField.ToField [GHC.Types.Char] instance Database.SQLite.Simple.ToField.ToField Data.Text.Internal.Lazy.Text instance Database.SQLite.Simple.ToField.ToField Data.Time.Clock.Internal.UTCTime.UTCTime instance Database.SQLite.Simple.ToField.ToField Data.Time.Calendar.Days.Day -- | The ToRow typeclass, for rendering a collection of parameters -- to a SQL query. -- -- Predefined instances are provided for tuples containing up to ten -- elements. module Database.SQLite.Simple.ToRow -- | A collection type that can be turned into a list of SQLData -- elements. class ToRow a -- | ToField a collection of values. toRow :: ToRow a => a -> [SQLData] instance Database.SQLite.Simple.ToRow.ToRow () instance Database.SQLite.Simple.ToField.ToField a => Database.SQLite.Simple.ToRow.ToRow (Data.Tuple.Only.Only a) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b) => Database.SQLite.Simple.ToRow.ToRow (a, b) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c) => Database.SQLite.Simple.ToRow.ToRow (a, b, c) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d, Database.SQLite.Simple.ToField.ToField e) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d, e) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d, Database.SQLite.Simple.ToField.ToField e, Database.SQLite.Simple.ToField.ToField f) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d, e, f) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d, Database.SQLite.Simple.ToField.ToField e, Database.SQLite.Simple.ToField.ToField f, Database.SQLite.Simple.ToField.ToField g) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d, e, f, g) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d, Database.SQLite.Simple.ToField.ToField e, Database.SQLite.Simple.ToField.ToField f, Database.SQLite.Simple.ToField.ToField g, Database.SQLite.Simple.ToField.ToField h) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d, e, f, g, h) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d, Database.SQLite.Simple.ToField.ToField e, Database.SQLite.Simple.ToField.ToField f, Database.SQLite.Simple.ToField.ToField g, Database.SQLite.Simple.ToField.ToField h, Database.SQLite.Simple.ToField.ToField i) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d, e, f, g, h, i) instance (Database.SQLite.Simple.ToField.ToField a, Database.SQLite.Simple.ToField.ToField b, Database.SQLite.Simple.ToField.ToField c, Database.SQLite.Simple.ToField.ToField d, Database.SQLite.Simple.ToField.ToField e, Database.SQLite.Simple.ToField.ToField f, Database.SQLite.Simple.ToField.ToField g, Database.SQLite.Simple.ToField.ToField h, Database.SQLite.Simple.ToField.ToField i, Database.SQLite.Simple.ToField.ToField j) => Database.SQLite.Simple.ToRow.ToRow (a, b, c, d, e, f, g, h, i, j) instance Database.SQLite.Simple.ToField.ToField a => Database.SQLite.Simple.ToRow.ToRow [a] instance (Database.SQLite.Simple.ToRow.ToRow a, Database.SQLite.Simple.ToRow.ToRow b) => Database.SQLite.Simple.ToRow.ToRow (a Database.SQLite.Simple.Types.:. b) -- | The sql quasiquoter, for writing large SQL statements. module Database.SQLite.Simple.QQ -- | A quasiquoter for writing big SQL queries. -- -- One should consider turning on the -XQuasiQuotes pragma in -- that module: -- --
--   myQuery = query conn [sql|
--       SELECT
--         *
--       FROM
--         users
--       WHERE jobTitle = ?
--       |] jobTitle
--   
sql :: QuasiQuoter -- | The FromField typeclass, for converting a single value in a row -- returned by a SQL query into a more useful Haskell representation. -- -- A Haskell numeric type is considered to be compatible with all SQLite -- numeric types that are less accurate than it. For instance, the -- Haskell Double type is compatible with the SQLite's 32-bit -- Int type because it can represent a Int exactly. On -- the other hand, since a Double might lose precision if -- representing a 64-bit BigInt, the two are not -- considered compatible. module Database.SQLite.Simple.FromField -- | A type that may be converted from a SQL type. class FromField a -- | Convert a SQL value to a Haskell value. -- -- Returns a list of exceptions if the conversion fails. In the case of -- library instances, this will usually be a single ResultError, -- but may be a UnicodeException. -- -- Implementations of fromField should not retain any references -- to the Field nor the ByteString arguments after the -- result has been evaluated to WHNF. Such a reference causes the entire -- LibPQ.Result to be retained. -- -- For example, the instance for ByteString uses copy to -- avoid such a reference, and that using bytestring functions such as -- drop and takeWhile alone will also trigger this memory -- leak. fromField :: FromField a => FieldParser a type FieldParser a = Field -> Ok a -- | Exception thrown if conversion from a SQL value to a Haskell value -- fails. data ResultError -- | The SQL and Haskell types are not compatible. Incompatible :: String -> String -> String -> ResultError [errSQLType] :: ResultError -> String [errHaskellType] :: ResultError -> String [errMessage] :: ResultError -> String -- | A SQL NULL was encountered when the Haskell type did not -- permit it. UnexpectedNull :: String -> String -> String -> ResultError [errSQLType] :: ResultError -> String [errHaskellType] :: ResultError -> String [errMessage] :: ResultError -> String -- | 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). ConversionFailed :: String -> String -> String -> ResultError [errSQLType] :: ResultError -> String [errHaskellType] :: ResultError -> String [errMessage] :: ResultError -> String -- | A Field represents metadata about a particular field data Field -- | Return the actual SQL data for a database field. This allows -- user-defined FromField instances to access the SQL data -- associated with a field being parsed. fieldData :: Field -> SQLData -- | Given one of the constructors from ResultError, the field, and -- an errMessage, this fills in the other fields in the exception -- value and returns it in a 'Left . SomeException' constructor. returnError :: forall a err. (Typeable a, Exception err) => (String -> String -> String -> err) -> Field -> String -> Ok a instance GHC.Show.Show Database.SQLite.Simple.FromField.ResultError instance GHC.Classes.Eq Database.SQLite.Simple.FromField.ResultError instance Database.SQLite.Simple.FromField.FromField a => Database.SQLite.Simple.FromField.FromField (GHC.Maybe.Maybe a) instance Database.SQLite.Simple.FromField.FromField Database.SQLite.Simple.Types.Null instance Database.SQLite.Simple.FromField.FromField GHC.Int.Int8 instance Database.SQLite.Simple.FromField.FromField GHC.Int.Int16 instance Database.SQLite.Simple.FromField.FromField GHC.Int.Int32 instance Database.SQLite.Simple.FromField.FromField GHC.Types.Int instance Database.SQLite.Simple.FromField.FromField GHC.Int.Int64 instance Database.SQLite.Simple.FromField.FromField GHC.Integer.Type.Integer instance Database.SQLite.Simple.FromField.FromField GHC.Word.Word8 instance Database.SQLite.Simple.FromField.FromField GHC.Word.Word16 instance Database.SQLite.Simple.FromField.FromField GHC.Word.Word32 instance Database.SQLite.Simple.FromField.FromField GHC.Word.Word64 instance Database.SQLite.Simple.FromField.FromField GHC.Types.Word instance Database.SQLite.Simple.FromField.FromField GHC.Types.Double instance Database.SQLite.Simple.FromField.FromField GHC.Types.Float instance Database.SQLite.Simple.FromField.FromField GHC.Types.Bool instance Database.SQLite.Simple.FromField.FromField Data.Text.Internal.Text instance Database.SQLite.Simple.FromField.FromField Data.Text.Internal.Lazy.Text instance Database.SQLite.Simple.FromField.FromField [GHC.Types.Char] instance Database.SQLite.Simple.FromField.FromField Data.ByteString.Internal.ByteString instance Database.SQLite.Simple.FromField.FromField Data.ByteString.Lazy.Internal.ByteString instance Database.SQLite.Simple.FromField.FromField Data.Time.Clock.Internal.UTCTime.UTCTime instance Database.SQLite.Simple.FromField.FromField Data.Time.Calendar.Days.Day instance Database.SQLite.Simple.FromField.FromField Database.SQLite3.SQLData instance GHC.Exception.Type.Exception Database.SQLite.Simple.FromField.ResultError -- | The FromRow typeclass, for converting a row of results returned -- by a SQL query into a more useful Haskell representation. -- -- Predefined instances are provided for tuples containing up to ten -- elements. module Database.SQLite.Simple.FromRow -- | 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. class FromRow a fromRow :: FromRow a => RowParser a data RowParser a field :: FromField a => RowParser a fieldWith :: FieldParser a -> RowParser a numFieldsRemaining :: RowParser Int instance Database.SQLite.Simple.FromField.FromField a => Database.SQLite.Simple.FromRow.FromRow (Data.Tuple.Only.Only a) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b) => Database.SQLite.Simple.FromRow.FromRow (a, b) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c) => Database.SQLite.Simple.FromRow.FromRow (a, b, c) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d, Database.SQLite.Simple.FromField.FromField e) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d, e) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d, Database.SQLite.Simple.FromField.FromField e, Database.SQLite.Simple.FromField.FromField f) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d, e, f) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d, Database.SQLite.Simple.FromField.FromField e, Database.SQLite.Simple.FromField.FromField f, Database.SQLite.Simple.FromField.FromField g) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d, e, f, g) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d, Database.SQLite.Simple.FromField.FromField e, Database.SQLite.Simple.FromField.FromField f, Database.SQLite.Simple.FromField.FromField g, Database.SQLite.Simple.FromField.FromField h) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d, e, f, g, h) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d, Database.SQLite.Simple.FromField.FromField e, Database.SQLite.Simple.FromField.FromField f, Database.SQLite.Simple.FromField.FromField g, Database.SQLite.Simple.FromField.FromField h, Database.SQLite.Simple.FromField.FromField i) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d, e, f, g, h, i) instance (Database.SQLite.Simple.FromField.FromField a, Database.SQLite.Simple.FromField.FromField b, Database.SQLite.Simple.FromField.FromField c, Database.SQLite.Simple.FromField.FromField d, Database.SQLite.Simple.FromField.FromField e, Database.SQLite.Simple.FromField.FromField f, Database.SQLite.Simple.FromField.FromField g, Database.SQLite.Simple.FromField.FromField h, Database.SQLite.Simple.FromField.FromField i, Database.SQLite.Simple.FromField.FromField j) => Database.SQLite.Simple.FromRow.FromRow (a, b, c, d, e, f, g, h, i, j) instance Database.SQLite.Simple.FromField.FromField a => Database.SQLite.Simple.FromRow.FromRow [a] instance (Database.SQLite.Simple.FromRow.FromRow a, Database.SQLite.Simple.FromRow.FromRow b) => Database.SQLite.Simple.FromRow.FromRow (a Database.SQLite.Simple.Types.:. b) module Database.SQLite.Simple -- | 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. newtype Query Query :: Text -> Query [fromQuery] :: Query -> Text -- | 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. newtype Connection Connection :: Database -> Connection [connectionHandle] :: Connection -> Database -- | A collection type that can be turned into a list of SQLData -- elements. class ToRow a -- | ToField a collection of values. toRow :: ToRow a => a -> [SQLData] -- | 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. class FromRow a fromRow :: FromRow a => RowParser a -- | 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) -> {- ... -}
--   
newtype Only a Only :: a -> Only a [fromOnly] :: Only a -> a -- | 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
--     ....
--   
data h :. t (:.) :: h -> t -> (:.) h t infixr 3 :. infixr 3 :. data SQLData SQLInteger :: !Int64 -> SQLData SQLFloat :: !Double -> SQLData SQLText :: !Text -> SQLData SQLBlob :: !ByteString -> SQLData SQLNull :: SQLData -- | An SQLite prepared statement. newtype Statement Statement :: Statement -> Statement [unStatement] :: Statement -> Statement -- | Index of a column in a result set. Column indices start from 0. newtype ColumnIndex ColumnIndex :: ColumnIndex -> ColumnIndex data NamedParam [:=] :: ToField v => Text -> v -> NamedParam infixr 3 := -- | 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. open :: String -> IO Connection -- | Close a database connection. close :: Connection -> IO () -- | Opens a database connection, executes an action using this connection, -- and closes the connection, even in the presence of exceptions. withConnection :: String -> (Connection -> IO a) -> IO a -- | 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! setTrace :: Connection -> Maybe (Text -> IO ()) -> IO () -- | Perform a SELECT or other SQL query that is expected to -- return results. All results are retrieved and converted before this -- function returns. -- -- When processing large results, this function will consume a lot of -- client-side memory. Consider using fold instead. -- -- Exceptions that may be thrown: -- -- query :: (ToRow q, FromRow r) => Connection -> Query -> q -> IO [r] -- | A version of query that does not perform query substitution. query_ :: FromRow r => Connection -> Query -> IO [r] -- | A version of query that takes an explicit RowParser. queryWith :: ToRow q => RowParser r -> Connection -> Query -> q -> IO [r] -- | A version of query that does not perform query substitution and -- takes an explicit RowParser. queryWith_ :: RowParser r -> Connection -> Query -> IO [r] -- | A version of query where the query parameters (placeholders) -- are named. -- -- Example: -- --
--   r <- queryNamed c "SELECT * FROM posts WHERE id=:id AND date>=:date" [":id" := postId, ":date" := afterDate]
--   
queryNamed :: FromRow r => Connection -> Query -> [NamedParam] -> IO [r] -- | 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. lastInsertRowId :: Connection -> IO Int64 -- | 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. changes :: 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. totalChanges :: Connection -> IO Int -- | 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: -- -- fold :: (FromRow row, ToRow params) => Connection -> Query -> params -> a -> (a -> row -> IO a) -> IO a -- | A version of fold which does not perform parameter -- substitution. fold_ :: FromRow row => Connection -> Query -> a -> (a -> row -> IO a) -> IO a -- | A version of fold where the query parameters (placeholders) are -- named. foldNamed :: FromRow row => Connection -> Query -> [NamedParam] -> a -> (a -> row -> IO a) -> IO a -- | Execute an INSERT, UPDATE, or other SQL query that -- is not expected to return results. -- -- Throws FormatError if the query could not be formatted -- correctly. execute :: ToRow q => Connection -> Query -> q -> IO () -- | A version of execute that does not perform query substitution. execute_ :: Connection -> Query -> IO () -- | Execute a multi-row INSERT, UPDATE, or other SQL -- query that is not expected to return results. -- -- Throws FormatError if the query could not be formatted -- correctly. executeMany :: ToRow q => Connection -> Query -> [q] -> IO () -- | A version of execute where the query parameters (placeholders) -- are named. executeNamed :: Connection -> Query -> [NamedParam] -> IO () field :: FromField a => RowParser a -- | Run an IO action inside a SQL transaction started with BEGIN -- TRANSACTION. 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. withTransaction :: 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. withImmediateTransaction :: 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. withExclusiveTransaction :: Connection -> IO a -> IO a -- | 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. openStatement :: Connection -> Query -> IO Statement -- | Closes a prepared statement. closeStatement :: Statement -> IO () -- | Opens a prepared statement, executes an action using this statement, -- and closes the statement, even in the presence of exceptions. withStatement :: Connection -> Query -> (Statement -> IO a) -> IO a -- | Binds parameters to a prepared statement. Once nextRow returns -- Nothing, the statement must be reset with the reset -- function before it can be executed again by calling nextRow. bind :: ToRow params => Statement -> params -> IO () -- | Binds named parameters to a prepared statement. bindNamed :: Statement -> [NamedParam] -> IO () -- | Resets a statement. This does not reset bound parameters, if any, but -- allows the statement to be reexecuted again by invoking -- nextRow. reset :: Statement -> IO () -- | 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. -- -- http://www.sqlite.org/c3ref/column_name.html columnName :: Statement -> ColumnIndex -> IO Text -- | Return number of columns in the query columnCount :: Statement -> IO ColumnIndex -- | Binds parameters to a prepared statement, and resets the -- statement when the callback completes, even in the presence of -- exceptions. -- -- Use withBind to reuse prepared statements. Because it -- resets 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. withBind :: ToRow params => Statement -> params -> IO a -> IO a -- | Extracts the next row from the prepared statement. nextRow :: FromRow r => Statement -> IO (Maybe r) -- | 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. data FormatError FormatError :: String -> Query -> [String] -> FormatError [fmtMessage] :: FormatError -> String [fmtQuery] :: FormatError -> Query [fmtParams] :: FormatError -> [String] -- | Exception thrown if conversion from a SQL value to a Haskell value -- fails. data ResultError -- | The SQL and Haskell types are not compatible. Incompatible :: String -> String -> String -> ResultError [errSQLType] :: ResultError -> String [errHaskellType] :: ResultError -> String [errMessage] :: ResultError -> String -- | A SQL NULL was encountered when the Haskell type did not -- permit it. UnexpectedNull :: String -> String -> String -> ResultError [errSQLType] :: ResultError -> String [errHaskellType] :: ResultError -> String [errMessage] :: ResultError -> String -- | 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). ConversionFailed :: String -> String -> String -> ResultError [errSQLType] :: ResultError -> String [errHaskellType] :: ResultError -> String [errMessage] :: ResultError -> String -- | Exception thrown when SQLite3 reports an error. -- -- direct-sqlite may throw other types of exceptions if you misuse the -- API. data SQLError SQLError :: !Error -> Text -> Text -> SQLError -- | Error code returned by API call [sqlError] :: SQLError -> !Error -- | Text describing the error [sqlErrorDetails] :: SQLError -> Text -- | Indicates what action produced this error, e.g. exec "SELECT * -- FROM foo" [sqlErrorContext] :: SQLError -> Text -- | https://www.sqlite.org/c3ref/c_abort.html data Error -- | Successful result ErrorOK :: Error -- | SQL error or missing database ErrorError :: Error -- | Internal logic error in SQLite ErrorInternal :: Error -- | Access permission denied ErrorPermission :: Error -- | Callback routine requested an abort ErrorAbort :: Error -- | The database file is locked ErrorBusy :: Error -- | A table in the database is locked ErrorLocked :: Error -- | A malloc() failed ErrorNoMemory :: Error -- | Attempt to write a readonly database ErrorReadOnly :: Error -- | Operation terminated by sqlite3_interrupt() ErrorInterrupt :: Error -- | Some kind of disk I/O error occurred ErrorIO :: Error -- | The database disk image is malformed ErrorCorrupt :: Error -- | Unknown opcode in sqlite3_file_control() ErrorNotFound :: Error -- | Insertion failed because database is full ErrorFull :: Error -- | Unable to open the database file ErrorCan'tOpen :: Error -- | Database lock protocol error ErrorProtocol :: Error -- | Database is empty ErrorEmpty :: Error -- | The database schema changed ErrorSchema :: Error -- | String or BLOB exceeds size limit ErrorTooBig :: Error -- | Abort due to constraint violation ErrorConstraint :: Error -- | Data type mismatch ErrorMismatch :: Error -- | Library used incorrectly ErrorMisuse :: Error -- | Uses OS features not supported on host ErrorNoLargeFileSupport :: Error -- | Authorization denied ErrorAuthorization :: Error -- | Auxiliary database format error ErrorFormat :: Error -- | 2nd parameter to sqlite3_bind out of range ErrorRange :: Error -- | File opened that is not a database file ErrorNotADatabase :: Error -- | Notifications from sqlite3_log() ErrorNotice :: Error -- | Warnings from sqlite3_log() ErrorWarning :: Error -- | sqlite3_step() has another row ready ErrorRow :: Error -- | sqlite3_step() has finished executing ErrorDone :: Error instance GHC.Show.Show Database.SQLite.Simple.FormatError instance GHC.Classes.Eq Database.SQLite.Simple.FormatError instance GHC.Real.Integral Database.SQLite.Simple.ColumnIndex instance GHC.Real.Real Database.SQLite.Simple.ColumnIndex instance GHC.Num.Num Database.SQLite.Simple.ColumnIndex instance GHC.Enum.Enum Database.SQLite.Simple.ColumnIndex instance GHC.Classes.Ord Database.SQLite.Simple.ColumnIndex instance GHC.Classes.Eq Database.SQLite.Simple.ColumnIndex instance GHC.Exception.Type.Exception Database.SQLite.Simple.FormatError instance GHC.Show.Show Database.SQLite.Simple.NamedParam module Database.SQLite.Simple.Function class Function a createFunction :: forall f. Function f => Connection -> Text -> f -> IO (Either Error ()) deleteFunction :: Connection -> Text -> IO (Either Error ()) instance Database.SQLite.Simple.ToField.ToField a => Database.SQLite.Simple.Function.Function a instance Database.SQLite.Simple.Function.Function a => Database.SQLite.Simple.Function.Function (GHC.Types.IO a) instance (Database.SQLite.Simple.Function.Function r, Database.SQLite.Simple.FromField.FromField f) => Database.SQLite.Simple.Function.Function (f -> r)