persistent-sql-lifted 0.3.0.0 → 0.4.0.0
raw patch · 5 files changed
+153/−28 lines, 5 filesdep −conduitdep ~persistent
Dependencies removed: conduit
Dependency ranges changed: persistent
Files
- CHANGELOG.md +18/−2
- library/Database/Persist/Sql/Lifted.hs +13/−1
- library/Database/Persist/Sql/Lifted/Persistent.hs +119/−20
- package.yaml +1/−2
- persistent-sql-lifted.cabal +2/−3
CHANGELOG.md view
@@ -1,5 +1,21 @@-## [_Unreleased_](https://github.com/freckle/persistent-sql-lifted/compare/persistent-sql-lifted-v0.3.0.0...main)+## [_Unreleased_](https://github.com/freckle/persistent-sql-lifted/compare/persistent-sql-lifted-v0.4.0.0...main) +## [v0.4.0.0](https://github.com/freckle/persistent-sql-lifted/compare/persistent-sql-lifted-v0.3.0.0...persistent-sql-lifted-v0.4.0.0)++Remove `selectKeys` because Persistent's Conduit-based utilities are of dubious correctness.++Add:++- `deleteWhereCount`+- `existsBy`+- `getFieldName`+- `getTableName`+- `insertUnique_`+- `rawExecute`+- `rawExecuteCount`+- `rawSql`+- `updateWhereCount`+ ## [v0.3.0.0](https://github.com/freckle/persistent-sql-lifted/compare/persistent-sql-lifted-v0.2.0.0...persistent-sql-lifted-v0.3.0.0) Remove `rand`; supports `esqueleto-3.6`.@@ -47,6 +63,6 @@ - `transactionUndo` - `transactionUndoWithIsolation` -## [v0.1.0.0](https://github.com/freckle/persistent-sql-lifted/tree/persistent-sql-lifted-v0.0.0.0/persistent-sql-lifted)+## [v0.1.0.0](https://github.com/freckle/persistent-sql-lifted/tree/persistent-sql-lifted-v0.1.0.0/persistent-sql-lifted) First release, sprouted from `freckle-app-1.20.3.0`.
library/Database/Persist/Sql/Lifted.hs view
@@ -34,13 +34,13 @@ , select , selectOne , selectFirst- , selectKeys , selectKeysList , selectList -- * Selecting counts/existence , count , exists+ , existsBy -- * Inserting , insertSelect@@ -55,6 +55,7 @@ , insertMany_ , insertRecord , insertUnique+ , insertUnique_ , insertUniqueEntity -- * Updating@@ -63,6 +64,7 @@ , update' , updateGet , updateWhere+ , updateWhereCount -- * Insert/update combinations , replace@@ -84,12 +86,22 @@ , deleteBy , deleteWhere , deleteCount+ , deleteWhereCount -- * Transactions , transactionSave , transactionSaveWithIsolation , transactionUndo , transactionUndoWithIsolation++ -- * Raw SQL+ , rawSql+ , rawExecute+ , rawExecuteCount++ -- * Getting names+ , getFieldName+ , getTableName -- * Rendering queries to text , renderQueryDelete
library/Database/Persist/Sql/Lifted/Persistent.hs view
@@ -8,14 +8,18 @@ , delete , deleteBy , deleteWhere+ , deleteWhereCount , exists+ , existsBy , get , getBy , getByValue , getEntity+ , getFieldName , getJust , getJustEntity , getMany+ , getTableName , insert , insert_ , insertBy@@ -26,15 +30,18 @@ , insertMany_ , insertRecord , insertUnique+ , insertUnique_ , insertUniqueEntity , onlyUnique , putMany+ , rawExecute+ , rawExecuteCount+ , rawSql , replace , replaceUnique , repsert , repsertMany , selectFirst- , selectKeys , selectKeysList , selectList , transactionSave@@ -44,33 +51,35 @@ , update , updateGet , updateWhere+ , updateWhereCount , upsert , upsertBy ) where -import Conduit (ConduitT, MonadResource, transPipe) import Data.Bool (Bool) import Data.Either (Either) import Data.Eq (Eq) import Data.Function (($))-import Data.Int (Int)+import Data.Int (Int, Int64) import Data.Map.Strict (Map) import Data.Maybe (Maybe) #if MIN_VERSION_base(4,17,0) import Data.Type.Equality (type (~)) #endif+import Data.Text (Text) import Database.Persist ( AtLeastOneUniqueKey , Entity , Filter , OnlyOneUniqueKey , PersistEntity (..)+ , PersistValue , SelectOpt , Update ) import Database.Persist.Class qualified as P import Database.Persist.Class.PersistEntity (SafeToInsert)-import Database.Persist.Sql (IsolationLevel)+import Database.Persist.Sql (IsolationLevel, RawSql) import Database.Persist.Sql qualified as P import Database.Persist.Sql.Lifted.Core (MonadSqlBackend, SqlBackend, liftSql) import GHC.Stack (HasCallStack)@@ -160,6 +169,20 @@ -> m () deleteWhere fs = liftSql $ P.deleteWhere fs +-- | Delete all records matching the given criteria+deleteWhereCount+ :: forall a m+ . ( PersistEntity a+ , PersistEntityBackend a ~ SqlBackend+ , MonadSqlBackend m+ , HasCallStack+ )+ => [Filter a]+ -- ^ If you provide multiple values in the list, the conditions are ANDed together.+ -> m Int64+ -- ^ The number of rows affected+deleteWhereCount fs = liftSql $ P.deleteWhereCount fs+ -- | Check if there is at least one record fulfilling the given criteria exists :: forall a m@@ -173,6 +196,18 @@ -> m Bool exists fs = liftSql $ P.exists fs +-- | Check if a record with this unique key exists+existsBy+ :: forall a m+ . ( PersistEntity a+ , PersistEntityBackend a ~ SqlBackend+ , MonadSqlBackend m+ , HasCallStack+ )+ => Unique a+ -> m Bool+existsBy u = liftSql $ P.existsBy u+ -- | Get a record by identifier, if available get :: forall a m@@ -224,6 +259,18 @@ -> m (Maybe (Entity a)) getEntity k = liftSql $ P.getEntity k +-- | Get the SQL string for the field that an 'EntityField' represents+getFieldName+ :: forall a t m+ . ( PersistEntity a+ , PersistEntityBackend a ~ SqlBackend+ , MonadSqlBackend m+ , HasCallStack+ )+ => EntityField a t+ -> m Text+getFieldName f = liftSql $ P.getFieldName f+ -- | Get a record by identifier, if available, for a non-null (not 'Maybe') foreign key -- -- Unsafe unless your database is enforcing that the foreign key is valid.@@ -264,6 +311,11 @@ -> m (Map (Key a) a) getMany ks = liftSql $ P.getMany ks +-- | Get the SQL string for the table that a 'PersistEntity' represents+getTableName+ :: forall a m. (PersistEntity a, MonadSqlBackend m, HasCallStack) => a -> m Text+getTableName x = liftSql $ P.getTableName x+ -- | Create a new record in the database insert :: forall a m@@ -400,6 +452,21 @@ insertUnique a = liftSql $ P.insertUnique a -- | Create a new record in the database+insertUnique_+ :: forall a m+ . ( PersistEntity a+ , PersistEntityBackend a ~ SqlBackend+ , SafeToInsert a+ , MonadSqlBackend m+ , HasCallStack+ )+ => a+ -> m (Maybe ())+ -- ^ (), or 'Nothing' when the record couldn't be inserted because of a+ -- uniqueness constraint+insertUnique_ a = liftSql $ P.insertUnique_ a++-- | Create a new record in the database insertUniqueEntity :: forall a m . ( PersistEntity a@@ -443,6 +510,39 @@ -> m () putMany as = liftSql $ P.putMany as +-- | Execute a raw SQL statement+rawExecute+ :: forall m+ . (MonadSqlBackend m, HasCallStack)+ => Text+ -- ^ SQL statement, possibly with placeholders+ -> [PersistValue]+ -- ^ Values to fill the placeholders+ -> m ()+rawExecute t vs = liftSql $ P.rawExecute t vs++-- | Execute a raw SQL statement+rawExecuteCount+ :: forall m+ . (MonadSqlBackend m, HasCallStack)+ => Text+ -- ^ SQL statement, possibly with placeholders+ -> [PersistValue]+ -- ^ Values to fill the placeholders+ -> m Int64+ -- ^ The number of rows modified+rawExecuteCount t vs = liftSql $ P.rawExecuteCount t vs++rawSql+ :: forall a m+ . (RawSql a, MonadSqlBackend m, HasCallStack)+ => Text+ -- ^ SQL statement, possibly with placeholders+ -> [PersistValue]+ -- ^ Values to fill the placeholders+ -> m [a]+rawSql sql vals = liftSql $ P.rawSql sql vals+ -- | Replace the record in the database with the given key -- -- The result is undefined if such record does not exist.@@ -520,22 +620,6 @@ selectFirst fs os = liftSql $ P.selectFirst fs os -- | Get the 'Key's of all records matching the given criteria-selectKeys- :: forall a m- . ( PersistEntity a- , PersistEntityBackend a ~ SqlBackend- , MonadSqlBackend m- , MonadResource m- , HasCallStack- )- => [Filter a]- -- ^ If you provide multiple values in the list, the conditions are ANDed together.- -> [SelectOpt a]- -> ConduitT () (Key a) m ()- -- ^ Keys corresponding to the filters and options provided-selectKeys fs os = transPipe liftSql $ P.selectKeys fs os---- | Get the 'Key's of all records matching the given criteria selectKeysList :: forall a m . ( PersistEntity a@@ -630,6 +714,21 @@ -> [Update a] -> m () updateWhere fs us = liftSql $ P.updateWhere fs us++-- | Update individual fields on any record matching the given criteria+updateWhereCount+ :: forall a m+ . ( PersistEntity a+ , PersistEntityBackend a ~ SqlBackend+ , MonadSqlBackend m+ , HasCallStack+ )+ => [Filter a]+ -- ^ If you provide multiple values in the list, the conditions are ANDed together.+ -> [Update a]+ -> m Int64+ -- ^ The number of rows affected+updateWhereCount fs us = liftSql $ P.updateWhereCount fs us -- | Update based on a uniqueness constraint or insert: --
package.yaml view
@@ -1,5 +1,5 @@ name: persistent-sql-lifted-version: 0.3.0.0+version: 0.4.0.0 maintainer: Freckle Education category: Database@@ -59,7 +59,6 @@ source-dirs: library dependencies: - annotated-exception- - conduit - containers - esqueleto - mtl
persistent-sql-lifted.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: persistent-sql-lifted-version: 0.3.0.0+version: 0.4.0.0 license: MIT license-file: LICENSE maintainer: Freckle Education@@ -87,11 +87,10 @@ build-depends: annotated-exception >=0.2.0.4, base >=4.16.4.0 && <5,- conduit >=1.3.5, containers >=0.6.5.1, esqueleto >=3.5.10.0, mtl >=2.2.2,- persistent >=2.14.0.1,+ persistent >=2.14.5.0, text >=1.2.5.0, unliftio-core >=0.2.1.0