persistent-sqlite 0.3.0.1 → 0.4.0
raw patch · 3 files changed
+31/−21 lines, 3 filesdep +monad-peeldep +textdep −neitherdep −utf8-stringdep ~persistentdep ~template-haskell
Dependencies added: monad-peel, text
Dependencies removed: neither, utf8-string
Dependency ranges changed: persistent, template-haskell
Files
- Database/Persist/Sqlite.hs +6/−4
- Database/Sqlite.hs +15/−7
- persistent-sqlite.cabal +10/−10
Database/Persist/Sqlite.hs view
@@ -18,15 +18,16 @@ import Data.List (intercalate) import Data.IORef import qualified Data.Map as Map-import Control.Monad.Invert (MonadInvertIO, finally)+import Control.Monad.IO.Peel (MonadPeelIO)+import Control.Exception.Peel (finally) -withSqlitePool :: MonadInvertIO m+withSqlitePool :: MonadPeelIO m => String -> Int -- ^ number of connections to open -> (ConnectionPool -> m a) -> m a withSqlitePool s = withSqlPool $ open' s -withSqliteConn :: MonadInvertIO m => String -> (Connection -> m a) -> m a+withSqliteConn :: MonadPeelIO m => String -> (Connection -> m a) -> m a withSqliteConn = withSqlConn . open' open' :: String -> IO Connection@@ -49,6 +50,7 @@ helper t getter = do stmt <- getter t execute stmt []+ reset stmt prepare' :: Sqlite.Connection -> String -> IO Statement prepare' conn sql = do@@ -81,7 +83,7 @@ Sqlite.Done <- Sqlite.step stmt return () -withStmt' :: MonadInvertIO m+withStmt' :: MonadPeelIO m => Sqlite.Statement -> [PersistValue] -> (RowPopper m -> m a)
Database/Sqlite.hs view
@@ -29,10 +29,12 @@ import qualified Prelude import qualified Data.ByteString as BS import qualified Data.ByteString.Internal as BSI-import qualified Data.ByteString.UTF8 as UTF8 import Foreign import Foreign.C import Database.Persist.Base (PersistValue (..))+import Data.Text (pack, unpack)+import Data.Text.Encoding (encodeUtf8, decodeUtf8With)+import Data.Text.Encoding.Error (lenientDecode) newtype Connection = Connection (Ptr ()) newtype Statement = Statement (Ptr ())@@ -123,8 +125,14 @@ errmsg (Connection database) = do message <- errmsgC database byteString <- BS.packCString message- return $ UTF8.toString byteString+ return $ toString byteString +toString :: BSI.ByteString -> String+toString = unpack . decodeUtf8With lenientDecode++fromString :: String -> BSI.ByteString+fromString = encodeUtf8 . pack+ sqlError :: Maybe Connection -> String -> Error -> IO a sqlError maybeConnection functionName error = do details <- case maybeConnection of@@ -140,7 +148,7 @@ openC :: CString -> Ptr (Ptr ()) -> IO Int openError :: String -> IO (Either Connection Error) openError path' = do- BS.useAsCString (UTF8.fromString path')+ BS.useAsCString (fromString path') (\path -> do alloca (\database -> do error' <- openC path database@@ -174,7 +182,7 @@ prepareC :: Ptr () -> CString -> Int -> Ptr (Ptr ()) -> Ptr (Ptr ()) -> IO Int prepareError :: Connection -> String -> IO (Either Statement Error) prepareError (Connection database) text' = do- BS.useAsCString (UTF8.fromString text')+ BS.useAsCString (fromString text') (\text -> do alloca (\statement -> do error' <- prepareC database text (-1) statement nullPtr@@ -216,7 +224,7 @@ error <- resetError statement case error of ErrorOK -> return ()- _ -> return () -- sqlError Nothing "reset" error+ _ -> return () -- FIXME confirm this is correct sqlError Nothing "reset" error foreign import ccall "sqlite3_finalize" finalizeC :: Ptr () -> IO Int@@ -304,7 +312,7 @@ bindTextC :: Ptr () -> Int -> CString -> Int -> Ptr () -> IO Int bindTextError :: Statement -> Int -> String -> IO Error bindTextError (Statement statement) parameterIndex text = do- byteString <- return $ UTF8.fromString text+ byteString <- return $ fromString text size <- return $ BS.length byteString BS.useAsCString byteString (\dataC -> do@@ -374,7 +382,7 @@ columnText (Statement statement) columnIndex = do text <- columnTextC statement columnIndex byteString <- BS.packCString text- return $ UTF8.toString byteString+ return $ toString byteString foreign import ccall "sqlite3_column_count" columnCountC :: Ptr () -> IO Int
persistent-sqlite.cabal view
@@ -1,12 +1,12 @@ name: persistent-sqlite-version: 0.3.0.1+version: 0.4.0 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com> maintainer: Michael Snoyman <michael@snoyman.com> synopsis: Backend for the persistent library using sqlite3. description: This package includes a thin sqlite3 wrapper based on the direct-sqlite package, as well as the entire C library, so there are no system dependencies.-category: Database+category: Database, Yesod stability: Stable cabal-version: >= 1.6 build-type: Simple@@ -17,14 +17,14 @@ default: False library- build-depends: base >= 4 && < 5,- template-haskell >= 2.4 && < 2.6,- bytestring >= 0.9.1 && < 0.10,- transformers >= 0.2.1 && < 0.3,- utf8-string >= 0.3.4 && < 0.4,- persistent >= 0.3.0 && < 0.4,- neither >= 0.1 && < 0.2,- containers >= 0.2 && < 0.5+ build-depends: base >= 4 && < 5+ , template-haskell+ , bytestring >= 0.9.1 && < 0.10+ , transformers >= 0.2.1 && < 0.3+ , persistent >= 0.4 && < 0.5+ , monad-peel >= 0.1 && < 0.2+ , containers >= 0.2 && < 0.5+ , text >= 0.7 && < 0.12 exposed-modules: Database.Sqlite Database.Persist.Sqlite ghc-options: -Wall