use stack 8.10 by default, support pers2.13

This commit is contained in:
parsonsmatt 2021-04-09 08:39:57 -06:00
parent 7a0649e449
commit ed61e90cf0
6 changed files with 13 additions and 12 deletions

View File

@ -13,8 +13,7 @@ extra-source-files:
dependencies: dependencies:
- base - base
- esqueleto - esqueleto
- persistent - persistent >= 2.12
- persistent-template
- persistent-postgresql - persistent-postgresql
- mtl - mtl
- monad-logger - monad-logger

View File

@ -16,6 +16,7 @@ import qualified Data.Set as Set
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Database.Persist.Sql import Database.Persist.Sql
import Database.Persist.SqlBackend
-- | A type representing the access of a table value. In Esqueleto, we get -- | A type representing the access of a table value. In Esqueleto, we get
-- a guarantee that the access will look something like: -- a guarantee that the access will look something like:
@ -43,7 +44,7 @@ parseOnExpr sqlBackend text = do
-- with postgresql, mysql, and sqlite backends. -- with postgresql, mysql, and sqlite backends.
mkEscapeChar :: SqlBackend -> Either String Char mkEscapeChar :: SqlBackend -> Either String Char
mkEscapeChar sqlBackend = mkEscapeChar sqlBackend =
case Text.uncons (connEscapeRawName sqlBackend "") of case Text.uncons (getEscapedRawName "" sqlBackend) of
Nothing -> Nothing ->
Left "Failed to get an escape character from the SQL backend." Left "Failed to get an escape character from the SQL backend."
Just (c, _) -> Just (c, _) ->
@ -63,9 +64,9 @@ skipToEscape escapeChar = void (takeWhile (/= escapeChar))
parseEscapedIdentifier :: ExprParser [Char] parseEscapedIdentifier :: ExprParser [Char]
parseEscapedIdentifier escapeChar = do parseEscapedIdentifier escapeChar = do
char escapeChar _ <- char escapeChar
str <- parseEscapedChars escapeChar str <- parseEscapedChars escapeChar
char escapeChar _ <- char escapeChar
pure str pure str
parseTableAccess :: ExprParser TableAccess parseTableAccess :: ExprParser TableAccess

View File

@ -55,6 +55,7 @@ import qualified Data.Text.Lazy.Builder as TLB
import Data.Typeable (Typeable) import Data.Typeable (Typeable)
import Database.Esqueleto.Internal.ExprParser (TableAccess(..), parseOnExpr) import Database.Esqueleto.Internal.ExprParser (TableAccess(..), parseOnExpr)
import Database.Esqueleto.Internal.PersistentImport import Database.Esqueleto.Internal.PersistentImport
import Database.Persist.SqlBackend
import qualified Database.Persist import qualified Database.Persist
import Database.Persist (FieldNameDB(..), EntityNameDB(..)) import Database.Persist (FieldNameDB(..), EntityNameDB(..))
import Database.Persist.Sql.Util import Database.Persist.Sql.Util
@ -1809,7 +1810,7 @@ instance Show FromClause where
"(FromIdent " <> show ident <> ")" "(FromIdent " <> show ident <> ")"
where where
dummy = SqlBackend dummy = mkSqlBackend MkSqlBackendArgs
{ connEscapeRawName = id { connEscapeRawName = id
} }
render' = T.unpack . renderExpr dummy render' = T.unpack . renderExpr dummy
@ -2145,7 +2146,7 @@ sub :: PersistField a => Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value
sub mode query = ERaw Parens $ \info -> toRawSql mode info query sub mode query = ERaw Parens $ \info -> toRawSql mode info query
fromDBName :: IdentInfo -> DBName -> TLB.Builder fromDBName :: IdentInfo -> DBName -> TLB.Builder
fromDBName (conn, _) = TLB.fromText . connEscapeRawName conn . unDBName fromDBName (conn, _) = TLB.fromText . flip getEscapedRawName conn . unDBName
existsHelper :: SqlQuery () -> SqlExpr (Value Bool) existsHelper :: SqlQuery () -> SqlExpr (Value Bool)
existsHelper = sub SELECT . (>> return true) existsHelper = sub SELECT . (>> return true)
@ -3010,8 +3011,7 @@ makeOrderBy info is =
makeLimit :: IdentInfo -> LimitClause -> [OrderByClause] -> (TLB.Builder, [PersistValue]) makeLimit :: IdentInfo -> LimitClause -> [OrderByClause] -> (TLB.Builder, [PersistValue])
makeLimit (conn, _) (Limit ml mo) orderByClauses = makeLimit (conn, _) (Limit ml mo) orderByClauses =
let limitRaw = connLimitOffset conn (v ml, v mo) hasOrderClause "\n" let limitRaw = getConnLimitOffset (v ml, v mo) "\n" conn
hasOrderClause = not (null orderByClauses)
v = maybe 0 fromIntegral v = maybe 0 fromIntegral
in (TLB.fromText limitRaw, mempty) in (TLB.fromText limitRaw, mempty)

View File

@ -48,6 +48,7 @@ import Database.Esqueleto.Internal.Internal hiding (random_)
import Database.Esqueleto.Internal.PersistentImport hiding (upsert, upsertBy) import Database.Esqueleto.Internal.PersistentImport hiding (upsert, upsertBy)
import Database.Persist.Class (OnlyOneUniqueKey) import Database.Persist.Class (OnlyOneUniqueKey)
import Database.Persist (ConstraintNameDB(..), EntityNameDB(..)) import Database.Persist (ConstraintNameDB(..), EntityNameDB(..))
import Database.Persist.SqlBackend
-- | (@random()@) Split out into database specific modules -- | (@random()@) Split out into database specific modules
-- because MySQL uses `rand()`. -- because MySQL uses `rand()`.
@ -207,7 +208,7 @@ upsertBy
-- ^ the record in the database after the operation -- ^ the record in the database after the operation
upsertBy uniqueKey record updates = do upsertBy uniqueKey record updates = do
sqlB <- R.ask sqlB <- R.ask
case connUpsertSql sqlB of case getConnUpsertSql sqlB of
Nothing -> Nothing ->
-- Postgres backend should have connUpsertSql, if this error is -- Postgres backend should have connUpsertSql, if this error is
-- thrown, check changes on persistent -- thrown, check changes on persistent

View File

@ -6,7 +6,7 @@ packages:
extra-deps: extra-deps:
- git: git@github.com:yesodweb/persistent - git: git@github.com:yesodweb/persistent
commit: 3e2975d7110b5330f987e1ceef747c43d0c6e0a9 commit: f7ad9b05a1ee899c6800962cbc795b39d01c5643
subdirs: subdirs:
- persistent - persistent
- persistent-sqlite - persistent-sqlite

View File

@ -1 +1 @@
stack-8.8.yaml stack-8.10.yaml