persistent-sqlite 0.9.0.2 → 1.0.0
raw patch · 4 files changed
+24/−18 lines, 4 filesdep ~conduitdep ~persistent
Dependency ranges changed: conduit, persistent
Files
- Database/Persist/Sqlite.hs +19/−14
- Database/Sqlite.hs +2/−1
- cbits/sqlite3.c too large to diff
- persistent-sqlite.cabal +3/−3
Database/Persist/Sqlite.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE ScopedTypeVariables #-} -- | A sqlite backend for persistent. module Database.Persist.Sqlite ( withSqlitePool@@ -37,7 +38,7 @@ import Control.Monad (mzero) import Data.Aeson import qualified Data.Text as T-import qualified Data.Conduit as C+import Data.Conduit import qualified Data.Conduit.List as CL import Control.Applicative @@ -66,7 +67,7 @@ , migrateSql = migrate' , begin = helper "BEGIN" , commitC = helper "COMMIT"- , rollbackC = helper "ROLLBACK"+ , rollbackC = ignoreExceptions . helper "ROLLBACK" , escapeName = escape , noLimit = "LIMIT -1" }@@ -75,6 +76,7 @@ stmt <- getter t execute stmt [] reset stmt+ ignoreExceptions = E.handle (\(_ :: E.SomeException) -> return ()) prepare' :: Sqlite.Connection -> Text -> IO Statement prepare' conn sql = do@@ -108,32 +110,35 @@ return () withStmt'- :: C.MonadResource m+ :: MonadResource m => Sqlite.Statement -> [PersistValue]- -> C.Source m [PersistValue]-withStmt' stmt vals = C.sourceIO+ -> Source m [PersistValue]+withStmt' stmt vals = bracketP (Sqlite.bind stmt vals >> return stmt) Sqlite.reset- pull+ (const pull) where- pull _ = liftIO $ do- x <- Sqlite.step stmt+ pull = do+ x <- liftIO $ Sqlite.step stmt case x of- Sqlite.Done -> return C.IOClosed+ Sqlite.Done -> return () Sqlite.Row -> do cols <- liftIO $ Sqlite.columns stmt- return $ C.IOOpen cols+ yield cols+ pull showSqlType :: SqlType -> String showSqlType SqlString = "VARCHAR" showSqlType SqlInt32 = "INTEGER"-showSqlType SqlInteger = "INTEGER"+showSqlType SqlInt64 = "INTEGER" showSqlType SqlReal = "REAL" showSqlType SqlDay = "DATE" showSqlType SqlTime = "TIME"+showSqlType SqlDayTimeZoned = "TIMESTAMP" showSqlType SqlDayTime = "TIMESTAMP" showSqlType SqlBlob = "BLOB" showSqlType SqlBool = "BOOLEAN"+showSqlType (SqlOther t) = T.unpack t migrate' :: PersistEntity val => [EntityDef]@@ -144,8 +149,8 @@ let (cols, uniqs) = mkColumns allDefs val let newSql = mkCreateTable False def (cols, uniqs) stmt <- getter "SELECT sql FROM sqlite_master WHERE type='table' AND name=?"- oldSql' <- C.runResourceT- $ withStmt stmt [PersistText $ unDBName table] C.$$ go+ oldSql' <- runResourceT+ $ withStmt stmt [PersistText $ unDBName table] $$ go case oldSql' of Nothing -> return $ Right [(False, newSql)] Just oldSql ->@@ -171,7 +176,7 @@ -> IO [(Bool, Sql)] getCopyTable allDefs getter val = do stmt <- getter $ pack $ "PRAGMA table_info(" ++ escape' table ++ ")"- oldCols' <- C.runResourceT $ withStmt stmt [] C.$$ getCols+ oldCols' <- runResourceT $ withStmt stmt [] $$ getCols let oldCols = map DBName $ filter (/= "id") oldCols' -- need to update for table id attribute ? let newCols = map cName cols let common = filter (`elem` oldCols) newCols
Database/Sqlite.hs view
@@ -33,7 +33,7 @@ import qualified Data.ByteString.Internal as BSI import Foreign import Foreign.C-import Database.Persist.Store (PersistValue (..), listToJSON, mapToJSON)+import Database.Persist.Store (PersistValue (..), listToJSON, mapToJSON, ZT (ZT)) import Data.Text (Text, pack, unpack) import Data.Text.Encoding (encodeUtf8, decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode)@@ -341,6 +341,7 @@ PersistDay d -> bindText statement parameterIndex $ pack $ show d PersistTimeOfDay d -> bindText statement parameterIndex $ pack $ show d PersistUTCTime d -> bindText statement parameterIndex $ pack $ show d+ PersistZonedTime (ZT d) -> bindText statement parameterIndex $ pack $ show d PersistList l -> bindText statement parameterIndex $ listToJSON l PersistMap m -> bindText statement parameterIndex $ mapToJSON m PersistObjectId _ -> P.error "Refusing to serialize a PersistObjectId to a SQLite value"
cbits/sqlite3.c view
file too large to diff
persistent-sqlite.cabal view
@@ -1,5 +1,5 @@ name: persistent-sqlite-version: 0.9.0.2+version: 1.0.0 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -20,12 +20,12 @@ build-depends: base >= 4 && < 5 , bytestring >= 0.9.1 , transformers >= 0.2.1 && < 0.4- , persistent >= 0.9 && < 0.10+ , persistent >= 1.0 && < 1.1 , monad-control >= 0.2 && < 0.4 , containers >= 0.2 , text >= 0.7 && < 1 , aeson >= 0.5- , conduit >= 0.4 && < 0.5+ , conduit >= 0.5 && < 0.6 exposed-modules: Database.Sqlite Database.Persist.Sqlite ghc-options: -Wall