yesodweb / yesodweb/persistent
updateWhere with SelectOpt
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
Currently selectList, updateWhere types is following:
selectList :: [Filter val] -> [SelectOpt val] -> ReaderT backend m [Entity val]
updateWhere :: [Filter val] -> [Update val] -> ReaderT backend m ()
But, I want to this.
updateWhere :: [Filter val] -> [Update val] -> [SelectOpt val] -> ReaderT backend m ()
Because, ran into this problem.
#!/usr/bin/env stack
-- stack --resolver lts-9.1 --install-ghc runghc --package persistent --package persistent-sqlite
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Monad.IO.Class (liftIO)
import Database.Persist
import Database.Persist.Sqlite
import Database.Persist.TH
share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase|
Item
name String
order Int
deriving Show
UniqueOrder order
|]
main :: IO ()
main =
runSqlite ":memory:" $ do
runMigration migrateAll
t1 <- insert $ Item "test1" 1
t2 <- insert $ Item "test2" 2
t3 <- insert $ Item "test3" 3
updateWhere [] [ItemOrder +=. 1] -- NG uniqueness error
updateWhere [] [ItemOrder -=. 1] -- OK
items <- selectList [] []
liftIO $ print (items :: [Entity Item])
deleteWhere ([] :: [Filter Item])
Error message;
test.hs: SQLite3 returned ErrorConstraint while attempting to perform step.
If can write updateWhere [] [ItemOrder +=. 1] [Desc ItemOrder] then nothing problem.
mysql 5.6 suport this syntax.
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET assignment_list
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
I tried make function updateWhereWithOpt, but many used internal functions.
- Referenced to Persist.Sql.Orphan.PersistQuery.hs
Can I submit PR?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in persistent/Database/Persist/Sql/Orphan/PersistQuery.hs around the referenced update functions and compare how selectList handles SelectOpt values. Use the supplied SQLite reproduction to define done: updateWhere accepts ordering options and the ordered increment avoids the uniqueness error, with the supported backend behavior covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100