packages feed

persistent-sqlite 0.6.1 → 0.6.2

raw patch · 2 files changed

+38/−2 lines, 2 filesdep +data-objectdep +neitherdep ~persistent

Dependencies added: data-object, neither

Dependency ranges changed: persistent

Files

Database/Persist/Sqlite.hs view
@@ -1,10 +1,12 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeFamilies #-} -- | A sqlite backend for persistent. module Database.Persist.Sqlite     ( withSqlitePool     , withSqliteConn     , module Database.Persist     , module Database.Persist.GenericSql+    , SqliteConf (..)     ) where  import Database.Persist@@ -21,6 +23,8 @@ import Control.Monad.IO.Control (MonadControlIO) import Control.Exception.Control (finally) import Data.Text (Text, pack, unpack)+import Data.Neither (MEither (..), meither)+import Data.Object  withSqlitePool :: MonadControlIO m                => Text@@ -236,3 +240,33 @@     go "" = ""     go ('"':xs) = "\"\"" ++ go xs     go (x:xs) = x : go xs++-- | Information required to connect to a sqlite database+data SqliteConf = SqliteConf+    { sqlDatabase :: Text+    , sqlPoolSize :: Int+    }++instance PersistConfig SqliteConf where+    type PersistConfigBackend SqliteConf = SqlPersist+    type PersistConfigPool SqliteConf = ConnectionPool+    withPool (SqliteConf cs size) = withSqlitePool cs size+    runPool _ = runSqlPool+    loadConfig e' = meither Left Right $ do+        e <- go $ fromMapping e'+        db <- go $ lookupScalar "database" e+        pool' <- go $ lookupScalar "poolsize" e+        pool <- safeRead "poolsize" pool'++        return $ SqliteConf db pool+      where+        go :: MEither ObjectExtractError a -> MEither String a+        go (MLeft e) = MLeft $ show e+        go (MRight a) = MRight a++safeRead :: String -> Text -> MEither String Int+safeRead name t = case reads s of+    (i, _):_ -> MRight i+    []       -> MLeft $ concat ["Invalid value for ", name, ": ", s]+  where+    s = unpack t
persistent-sqlite.cabal view
@@ -1,5 +1,5 @@ name:            persistent-sqlite-version:         0.6.1+version:         0.6.2 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>@@ -20,10 +20,12 @@     build-depends:   base                    >= 4         && < 5                    , bytestring              >= 0.9.1     && < 0.10                    , transformers            >= 0.2.1     && < 0.3-                   , persistent              >= 0.6       && < 0.7+                   , persistent              >= 0.6.3     && < 0.7                    , monad-control           >= 0.2       && < 0.3                    , containers              >= 0.2       && < 0.5                    , text                    >= 0.7       && < 0.12+                   , data-object             >= 0.3       && < 0.4+                   , neither                 >= 0.3       && < 0.4     exposed-modules: Database.Sqlite                      Database.Persist.Sqlite     ghc-options:     -Wall