packages feed

persistent-sqlite 2.1.1 → 2.1.1.1

raw patch · 4 files changed

+63/−2 lines, 4 filesdep +hspecdep +old-localedep +persistent-templatedep ~basedep ~persistentdep ~transformers

Dependencies added: hspec, old-locale, persistent-template, time

Dependency ranges changed: base, persistent, transformers

Files

ChangeLog.md view
@@ -1,3 +1,8 @@+## 2.1.1.1++Fix rendering of `UTCTime` to match SQLite requirements (see [issue+#328](https://github.com/yesodweb/persistent/issues/328#issuecomment-65887577)).+ ## 2.1.1  Provide a `FromJSON` instance for `SqliteConf`.
Database/Sqlite.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ForeignFunctionInterface, DeriveDataTypeable #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP #-} -- | A port of the direct-sqlite package for dealing directly with -- 'PersistValue's. module Database.Sqlite  (@@ -42,7 +43,14 @@ import Data.Monoid (mappend, mconcat) import Data.IORef (IORef, newIORef, readIORef, writeIORef) import Data.Fixed (Pico)+import Data.Time (formatTime, UTCTime) +#if MIN_VERSION_time(1,5,0)+import Data.Time (defaultTimeLocale)+#else+import System.Locale (defaultTimeLocale)+#endif+ data Connection = Connection !(IORef Bool) Connection' newtype Connection' = Connection' (Ptr ()) newtype Statement = Statement (Ptr ())@@ -358,7 +366,7 @@             PersistNull -> bindNull statement parameterIndex             PersistDay d -> bindText statement parameterIndex $ pack $ show d             PersistTimeOfDay d -> bindText statement parameterIndex $ pack $ show d-            PersistUTCTime d -> bindText statement parameterIndex $ pack $ show d+            PersistUTCTime d -> bindText statement parameterIndex $ pack $ format8601 d             PersistList l -> bindText statement parameterIndex $ listToJSON l             PersistMap m -> bindText statement parameterIndex $ mapToJSON m             PersistDbSpecific s -> bindText statement parameterIndex $ decodeUtf8With lenientDecode s@@ -366,6 +374,9 @@             )        $ zip [1..] sqlData   return ()++format8601 :: UTCTime -> String+format8601 = formatTime defaultTimeLocale "%FT%T%Q"  foreign import ccall "sqlite3_column_type"   columnTypeC :: Ptr () -> Int -> IO Int
persistent-sqlite.cabal view
@@ -1,5 +1,5 @@ name:            persistent-sqlite-version:         2.1.1+version:         2.1.1.1 license:         MIT license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>@@ -33,6 +33,8 @@                    , conduit                 >= 0.5.3                    , monad-logger            >= 0.2.4                    , resourcet               >= 1.1+                   , time+                   , old-locale     exposed-modules: Database.Sqlite                      Database.Persist.Sqlite     ghc-options:     -Wall@@ -48,6 +50,19 @@ source-repository head   type:     git   location: git://github.com/yesodweb/persistent.git+++test-suite test+  type:           exitcode-stdio-1.0+  main-is:        Spec.hs+  hs-source-dirs: test+  build-depends:  base+                , hspec+                , persistent+                , persistent-sqlite+                , persistent-template+                , time+                , transformers  executable sanity     if flag(build-sanity-exe)
+ test/Spec.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE EmptyDataDecls             #-}+{-# LANGUAGE GADTs                      #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MultiParamTypeClasses      #-}+{-# LANGUAGE OverloadedStrings          #-}+{-# LANGUAGE QuasiQuotes                #-}+{-# LANGUAGE TemplateHaskell            #-}+{-# LANGUAGE TypeFamilies               #-}++import Control.Monad.IO.Class  (liftIO)+import Data.Time+import Database.Persist.Sqlite+import Database.Persist.TH+import Test.Hspec++share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|+Test+  time UTCTime+|]++asIO :: IO a -> IO a+asIO = id++main :: IO ()+main = hspec $ do+    it "issue #328" $ asIO $ runSqlite ":memory:" $ do+        runMigration migrateAll+        insert . Test $ read "2014-11-30 05:15:25.123"+        [Single x] <- rawSql "select strftime('%s%f',time) from test" []+        liftIO $ x `shouldBe` Just ("141732452525.123" :: String)