tests pass for insertSelectCount and I only raged at haskell-mode a teensy bit
This commit is contained in:
parent
99dfbc526b
commit
f7bdd78d2e
@ -85,6 +85,7 @@ module Database.Esqueleto
|
||||
, update
|
||||
, updateCount
|
||||
, insertSelect
|
||||
, insertSelectCount
|
||||
, insertSelectDistinct
|
||||
, (<#)
|
||||
, (<&>)
|
||||
|
||||
@ -28,6 +28,7 @@ module Database.Esqueleto.Internal.Sql
|
||||
, updateCount
|
||||
, insertSelectDistinct
|
||||
, insertSelect
|
||||
, insertSelectCount
|
||||
-- * The guts
|
||||
, unsafeSqlCase
|
||||
, unsafeSqlBinOp
|
||||
@ -1741,7 +1742,12 @@ to16 ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),(o,p)) = (a,b,c,d,e,f,g,h,i,j,k,
|
||||
-- | Insert a 'PersistField' for every selected value.
|
||||
insertSelect :: (MonadIO m, PersistEntity a) =>
|
||||
SqlQuery (SqlExpr (Insertion a)) -> SqlPersistT m ()
|
||||
insertSelect = liftM (const ()) . rawEsqueleto INSERT_INTO . fmap EInsertFinal
|
||||
insertSelect = liftM (const ()) . insertSelectCount
|
||||
|
||||
-- | Insert a 'PersistField' for every selected value, return the count afterward
|
||||
insertSelectCount :: (MonadIO m, PersistEntity a) =>
|
||||
SqlQuery (SqlExpr (Insertion a)) -> SqlPersistT m Int64
|
||||
insertSelectCount = rawEsqueleto INSERT_INTO . fmap EInsertFinal
|
||||
|
||||
|
||||
-- | Insert a 'PersistField' for every unique selected value.
|
||||
|
||||
12
test/Test.hs
12
test/Test.hs
@ -1208,6 +1208,18 @@ main = do
|
||||
ret <- select $ from (\(_::(SqlExpr (Entity BlogPost))) -> return countRows)
|
||||
liftIO $ ret `shouldBe` [Value (3::Int)]
|
||||
|
||||
describe "inserts by select, returns count" $ do
|
||||
it "IN works for insertSelectCount" $
|
||||
run $ do
|
||||
_ <- insert p1
|
||||
_ <- insert p2
|
||||
_ <- insert p3
|
||||
cnt <- insertSelectCount $ from $ \p -> do
|
||||
return $ BlogPost <# val "FakePost" <&> (p ^. PersonId)
|
||||
ret <- select $ from (\(_::(SqlExpr (Entity BlogPost))) -> return countRows)
|
||||
liftIO $ ret `shouldBe` [Value (3::Int)]
|
||||
liftIO $ cnt `shouldBe` 3
|
||||
|
||||
describe "Math-related functions" $ do
|
||||
it "rand returns result in random order" $
|
||||
run $ do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user