commit
352fca204c
@ -74,6 +74,7 @@ library
|
|||||||
, monad-logger
|
, monad-logger
|
||||||
, conduit >= 1.1
|
, conduit >= 1.1
|
||||||
, resourcet >= 1.1
|
, resourcet >= 1.1
|
||||||
|
, time >= 1.5.0.1 && <= 1.8.0.2
|
||||||
, blaze-html
|
, blaze-html
|
||||||
hs-source-dirs: src/
|
hs-source-dirs: src/
|
||||||
if impl(ghc >= 8.0)
|
if impl(ghc >= 8.0)
|
||||||
@ -101,6 +102,7 @@ test-suite test
|
|||||||
, persistent-template >= 2.1
|
, persistent-template >= 2.1
|
||||||
, monad-control
|
, monad-control
|
||||||
, monad-logger >= 0.3
|
, monad-logger >= 0.3
|
||||||
|
, time >= 1.5.0.1 && <= 1.8.0.2
|
||||||
|
|
||||||
-- This library
|
-- This library
|
||||||
, esqueleto
|
, esqueleto
|
||||||
|
|||||||
@ -7,11 +7,12 @@ module Database.Esqueleto.PostgreSQL
|
|||||||
( arrayAgg
|
( arrayAgg
|
||||||
, stringAgg
|
, stringAgg
|
||||||
, chr
|
, chr
|
||||||
|
, now_
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Database.Esqueleto.Internal.Language
|
import Database.Esqueleto.Internal.Language
|
||||||
import Database.Esqueleto.Internal.Sql
|
import Database.Esqueleto.Internal.Sql
|
||||||
|
import Data.Time.Clock (UTCTime)
|
||||||
|
|
||||||
-- | (@array_agg@) Concatenate input values, including @NULL@s,
|
-- | (@array_agg@) Concatenate input values, including @NULL@s,
|
||||||
-- into an array.
|
-- into an array.
|
||||||
@ -38,3 +39,6 @@ stringAgg expr delim = unsafeSqlFunction "string_agg" (expr, delim)
|
|||||||
-- /Since: 2.2.11/
|
-- /Since: 2.2.11/
|
||||||
chr :: SqlString s => SqlExpr (Value Int) -> SqlExpr (Value s)
|
chr :: SqlString s => SqlExpr (Value Int) -> SqlExpr (Value s)
|
||||||
chr = unsafeSqlFunction "chr"
|
chr = unsafeSqlFunction "chr"
|
||||||
|
|
||||||
|
now_ :: SqlExpr (Value UTCTime)
|
||||||
|
now_ = unsafeSqlValue "NOW()"
|
||||||
|
|||||||
26
test/Test.hs
26
test/Test.hs
@ -51,6 +51,7 @@ import qualified Data.List as L
|
|||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import qualified Data.Text.Lazy.Builder as TLB
|
import qualified Data.Text.Lazy.Builder as TLB
|
||||||
import qualified Database.Esqueleto.Internal.Sql as EI
|
import qualified Database.Esqueleto.Internal.Sql as EI
|
||||||
|
import Data.Time.Clock (getCurrentTime, diffUTCTime, NominalDiffTime)
|
||||||
|
|
||||||
|
|
||||||
-- Test schema
|
-- Test schema
|
||||||
@ -644,6 +645,23 @@ main = do
|
|||||||
#endif
|
#endif
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
#if defined(WITH_POSTGRESQL)
|
||||||
|
it "works with now" $
|
||||||
|
run $ do
|
||||||
|
nowDb <- select $ return EP.now_
|
||||||
|
nowUtc <- liftIO getCurrentTime
|
||||||
|
let halfSecond = realToFrac 0.5 :: NominalDiffTime
|
||||||
|
|
||||||
|
-- | Check the result is not null
|
||||||
|
liftIO $ nowDb `shouldSatisfy` (not . null)
|
||||||
|
|
||||||
|
-- | Unpack the now value
|
||||||
|
let (Value now: _) = nowDb
|
||||||
|
|
||||||
|
-- | Get the time diff and check it's less than half a second
|
||||||
|
liftIO $ diffUTCTime nowUtc now `shouldSatisfy` (< halfSecond)
|
||||||
|
#endif
|
||||||
|
|
||||||
it "works with round_" $
|
it "works with round_" $
|
||||||
run $ do
|
run $ do
|
||||||
ret <- select $ return $ round_ (val (16.2 :: Double))
|
ret <- select $ return $ round_ (val (16.2 :: Double))
|
||||||
@ -1140,9 +1158,8 @@ main = do
|
|||||||
on $ lord ^. LordId ==. deed ^. DeedOwnerId
|
on $ lord ^. LordId ==. deed ^. DeedOwnerId
|
||||||
groupBy (lord ^. LordId)
|
groupBy (lord ^. LordId)
|
||||||
return (lord ^. LordId, count $ deed ^. DeedId)
|
return (lord ^. LordId, count $ deed ^. DeedId)
|
||||||
liftIO $ ret `shouldBe` [ (Value l3k, Value 7)
|
liftIO $ ret `shouldMatchList` [ (Value l3k, Value 7)
|
||||||
, (Value l1k, Value 3) ]
|
, (Value l1k, Value 3) ]
|
||||||
|
|
||||||
it "GROUP BY works with HAVING" $
|
it "GROUP BY works with HAVING" $
|
||||||
run $ do
|
run $ do
|
||||||
p1k <- insert p1
|
p1k <- insert p1
|
||||||
@ -1484,6 +1501,9 @@ cleanDB = do
|
|||||||
delete $ from $ \(_ :: SqlExpr (Entity Follow)) -> return ()
|
delete $ from $ \(_ :: SqlExpr (Entity Follow)) -> return ()
|
||||||
delete $ from $ \(_ :: SqlExpr (Entity Person)) -> return ()
|
delete $ from $ \(_ :: SqlExpr (Entity Person)) -> return ()
|
||||||
|
|
||||||
|
delete $ from $ \(_ :: SqlExpr (Entity Deed)) -> return ()
|
||||||
|
delete $ from $ \(_ :: SqlExpr (Entity Lord)) -> return ()
|
||||||
|
|
||||||
delete $ from $ \(_ :: SqlExpr (Entity CcList)) -> return ()
|
delete $ from $ \(_ :: SqlExpr (Entity CcList)) -> return ()
|
||||||
|
|
||||||
delete $ from $ \(_ :: SqlExpr (Entity ArticleTag)) -> return ()
|
delete $ from $ \(_ :: SqlExpr (Entity ArticleTag)) -> return ()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user