Use now, clean a warn

This commit is contained in:
parsonsmatt 2019-10-29 08:53:13 -06:00
parent 55fec71ed4
commit 214f1906da

View File

@ -35,7 +35,7 @@ import Data.Time.Clock (UTCTime)
import Database.Esqueleto.Internal.Language hiding (random_) import Database.Esqueleto.Internal.Language hiding (random_)
import Database.Esqueleto.Internal.PersistentImport hiding (upsert, upsertBy) import Database.Esqueleto.Internal.PersistentImport hiding (upsert, upsertBy)
import Database.Esqueleto.Internal.Sql import Database.Esqueleto.Internal.Sql
import Database.Esqueleto.Internal.Internal (EsqueletoError(..), CompositeKeyError(..), import Database.Esqueleto.Internal.Internal (EsqueletoError(..), CompositeKeyError(..),
UnexpectedCaseError(..), SetClause, Ident(..), UnexpectedCaseError(..), SetClause, Ident(..),
uncommas, FinalResult(..), toUniqueDef, uncommas, FinalResult(..), toUniqueDef,
KnowResult, renderUpdates) KnowResult, renderUpdates)
@ -44,7 +44,7 @@ import Data.List.NonEmpty ( NonEmpty( (:|) )
import Data.Int (Int64) import Data.Int (Int64)
import Data.Proxy (Proxy(..)) import Data.Proxy (Proxy(..))
import Control.Arrow ((***), first) import Control.Arrow ((***), first)
import Control.Exception (Exception, throw, throwIO) import Control.Exception (throw)
import Control.Monad (void) import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.IO.Class (MonadIO (..))
import qualified Control.Monad.Trans.Reader as R import qualified Control.Monad.Trans.Reader as R
@ -169,7 +169,7 @@ chr :: SqlString s => SqlExpr (Value Int) -> SqlExpr (Value s)
chr = unsafeSqlFunction "chr" chr = unsafeSqlFunction "chr"
now_ :: SqlExpr (Value UTCTime) now_ :: SqlExpr (Value UTCTime)
now_ = unsafeSqlValue "NOW()" now_ = unsafeSqlFunction "NOW" ()
upsert :: (MonadIO m, upsert :: (MonadIO m,
PersistEntity record, PersistEntity record,
@ -200,7 +200,7 @@ upsertBy :: (MonadIO m,
upsertBy uniqueKey record updates = do upsertBy uniqueKey record updates = do
sqlB <- R.ask sqlB <- R.ask
maybe maybe
(throw (UnexpectedCaseErr OperationNotSupported)) -- Postgres backend should have connUpsertSql, if this error is thrown, check changes on persistent (throw (UnexpectedCaseErr OperationNotSupported)) -- Postgres backend should have connUpsertSql, if this error is thrown, check changes on persistent
(handler sqlB) (handler sqlB)
(connUpsertSql sqlB) (connUpsertSql sqlB)
where where
@ -230,7 +230,7 @@ upsertBy uniqueKey record updates = do
-- deriving Eq Show -- deriving Eq Show
-- |] -- |]
-- --
-- insertSelectWithConflict -- insertSelectWithConflict
-- UniqueFoo -- (UniqueFoo undefined) or (UniqueFoo anyNumber) would also work -- UniqueFoo -- (UniqueFoo undefined) or (UniqueFoo anyNumber) would also work
-- (from $ \b -> -- (from $ \b ->
-- return $ Foo <# (b ^. BarNum) -- return $ Foo <# (b ^. BarNum)
@ -240,18 +240,18 @@ upsertBy uniqueKey record updates = do
-- ) -- )
-- @ -- @
-- --
-- Inserts to table Foo all Bar.num values and in case of conflict SomeFooUnique, -- Inserts to table Foo all Bar.num values and in case of conflict SomeFooUnique,
-- the conflicting value is updated to the current plus the excluded. -- the conflicting value is updated to the current plus the excluded.
-- --
-- @since 3.1.3 -- @since 3.1.3
insertSelectWithConflict :: forall a m val. ( insertSelectWithConflict :: forall a m val. (
FinalResult a, FinalResult a,
KnowResult a ~ (Unique val), KnowResult a ~ (Unique val),
MonadIO m, MonadIO m,
PersistEntity val) => PersistEntity val) =>
a a
-- ^ Unique constructor or a unique, this is used just to get the name of the postgres constraint, the value(s) is(are) never used, so if you have a unique "MyUnique 0", "MyUnique undefined" would work as well. -- ^ Unique constructor or a unique, this is used just to get the name of the postgres constraint, the value(s) is(are) never used, so if you have a unique "MyUnique 0", "MyUnique undefined" would work as well.
-> SqlQuery (SqlExpr (Insertion val)) -> SqlQuery (SqlExpr (Insertion val))
-- ^ Insert query. -- ^ Insert query.
-> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)]) -> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)])
-- ^ A list of updates to be applied in case of the constraint being violated. The expression takes the current and excluded value to produce the updates. -- ^ A list of updates to be applied in case of the constraint being violated. The expression takes the current and excluded value to produce the updates.
@ -263,11 +263,11 @@ insertSelectWithConflict unique query = void . insertSelectWithConflictCount uni
-- @since 3.1.3 -- @since 3.1.3
insertSelectWithConflictCount :: forall a val m. ( insertSelectWithConflictCount :: forall a val m. (
FinalResult a, FinalResult a,
KnowResult a ~ (Unique val), KnowResult a ~ (Unique val),
MonadIO m, MonadIO m,
PersistEntity val) => PersistEntity val) =>
a a
-> SqlQuery (SqlExpr (Insertion val)) -> SqlQuery (SqlExpr (Insertion val))
-> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)]) -> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)])
-> SqlWriteT m Int64 -> SqlWriteT m Int64
insertSelectWithConflictCount unique query conflictQuery = do insertSelectWithConflictCount unique query conflictQuery = do
@ -292,7 +292,7 @@ insertSelectWithConflictCount unique query conflictQuery = do
TLB.fromText "ON CONFLICT ON CONSTRAINT \"", TLB.fromText "ON CONFLICT ON CONSTRAINT \"",
constraint, constraint,
TLB.fromText "\" DO " TLB.fromText "\" DO "
] ++ if null updates then [TLB.fromText "NOTHING"] else [ ] ++ if null updates then [TLB.fromText "NOTHING"] else [
TLB.fromText "UPDATE SET ", TLB.fromText "UPDATE SET ",
updatesTLB updatesTLB
]),values) ]),values)