persistent-template
Type-safe, non-relational, multi-backend persistence.
http://www.yesodweb.com/book/persistent
| LTS Haskell 24.16: | 2.12.0.0 |
| Stackage Nightly 2025-10-24: | 2.12.0.0 |
| Latest on Hackage: | 2.12.0.0 |
persistent-template-2.12.0.0@sha256:7c68de6624ff83e14b674745e1c895dcf7c8676f6f24be131c89e2e4c2fa4510,1008Module documentation for 2.12.0.0
There are no documented modules for this package.
Begone!
This package was absorbed into persistent with the 2.12.0.1 release.
persistent-template
Provides Template Haskell helpers for persistent. For more information, see the chapter in the Yesod book.
code organization
The TH.hs module contains code generators.
persistent-template uses EntityDefs that it gets from the quasi-quoter.
The quasi-quoter is in persistent Quasi.hs
Similarly many of the types come from the persistent library
Development tips
To get a better idea of what code you’re generating, you can output the content of Template Haskell expressions to a file:
stack test persistent-template --ghc-options='-ddump-splices -ddump-to-file'
The output will be in the .stack-work directory. The exact path will depend on your specific setup, but if you search for files ending in .dump-splices you’ll find the output (find .stack-work -type f -name '*.dump-splices')
If you make changes to the generated code, it is highly recommended to compare the output with your changes to output from master (even better if this diff is included in your PR!). Seemingly small changes can have dramatic changes on the generated code.
For example, embedding an EntityDef in a function that was called for every field of that Entity made the number of generated lines O(N^2) for that function—very bad!
Changes
Unreleased changes
2.12.0.0
- Decomposed
HaskellNameintoConstraintNameHS,EntityNameHS,FieldNameHS. DecomposedDBNameintoConstraintNameDB,EntityNameDB,FieldNameDBrespectively. #1174 - #1214:
- This package was asborbed into
persistentitself.
- This package was asborbed into
2.9.1.0
- #1145
- Fix a bug where the
SqlTypefor a shared primary key was being incorrectly set toSqlStringinstead of whatever the target primary key sql type was.
- Fix a bug where the
- #1151
- Automatically generate
SymbolToFieldinstances for datatypes, allowingOverloadedLabelsto be used with theEntityFieldtype.
- Automatically generate
2.9
-
Always use the “stock” strategy when deriving Show/Read for keys #1106
- This fixes a regression from 2.8.0, which started using the
newtypestrategy when derivingShow/Readfor keys - In practice, this means that from 2.8.0–2.8.3.1, for the following schema:
Person name Text CustomPrimary anInt Int Primary anInt name TextPersonKey 1would show as"SqlBackendKey {unSqlBackendKey = 1}"andCustomPrimaryKey 1would show as"1"This was generally poor for debugging and logging, since all tables keys would print the same. For Persistent < 2.8.0 and > 2.8.3.1, they instead will show as:
"PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 1}}"and"CustomPrimaryKey {unCustomPrimaryKey = 1}"This could be a breaking change if you have used
Showon a key, wrote that string into some persistent storage like a database, and are trying toReadit back again later. - This fixes a regression from 2.8.0, which started using the
2.8.3.1
- Allow aeson 1.5. #1085
2.8.3.0
- Add
Liftinstances for the cascade types. #1060 - Use
DeriveLiftto implement allLiftinstances. Among other benefits, this provides implementations ofliftTypedontemplate-haskell-2.16(GHC 8.10) or later. #1064
2.8.2.3
- Require extensions in a more friendly manner. #1030
- Specify a strategy for all deriving clauses, which avoids the
-Wmissing-deriving-strategywarning introduced in GHC 8.8.2. #1030
2.8.2.2
- Fix the
mkPersistfunction to not require importing the classes explicitly. #1027
2.8.2.1
- Fix the test-suite for persistent-template. #1023
2.8.2
- Add
fieldErrorto the export list ofDatabase.Persist.TH#1008
2.8.1
- Let the user pass instances that will be derived for record and for key types (https://github.com/yesodweb/persistent/pull/990
2.8.0.1
- Small optimization/code cleanup to generated Template Haskell code size, by slimming the implementation of to/fromPersistValue for Entities. #1014
2.8.0
- Reduces the amount of code generated by Template Haskell. The amount of code generated for a certain function was O(N^2) with respect to the number of fields on a given Entity. This change shows dramatic improvements in benchmarks for compiling Persistent models. #
- Drops support for GHC 8.0, so that
DerivingStrategiescan be used bypersistent-template persistent-templatenow requiresDerivingStrategies,GeneralizedNewtypeDeriving, andStandaloneDerivingto be enabled in the file where Persistent entities are created- Fixes a long-standing issue where persistent-template would fail when
DeriveAnyClasswas enabled (See #578) - #1002
2.7.4
- Remove an overlapping instance for
Lift a. #998
2.7.3
- Update module documentation for
Database.Persist.THto better describe the purpose of the module #968 - Support template-haskell-2.15 #959
2.7.2
- Expose the knot tying logic of
parseReferencesso that users can build migrations from independently define entities at runtime #932
2.7.1
2.7.0
- Depends on
persistent-2.10.0which provides theOnlyOneUniqueKeyandAtLeastOneUniqueKeyclasses. Automatically generates instances for these classes based on how many unique keys the entity definition gets. This changes requiresUndecidableInstancesto be enabled on each module that generates entity definitions. #885 - Removed deprecated
sqlOnlySettings. Please usesqlSettingsinstead. #894
2.6.0
- persistent#846: Improve error message when marshalling fails
- persistent#826: Change
UniquederiveShow
2.5.4
- persistent#778: Add
persistManyFileWith.
2.5.3.1
- Slight improvement to the error message when a Persistent field can’t be parsed from database results
2.5.3
- Exposed
parseReferencesto allow custom QuasiQuoters
2.5.2
- Fix incorrect
ToJSON/FromJSONinstance generation for generic backends
2.5.1.6
Allow non-null self-references in a list
2.5.1.4
- Allow composite Primary keys for tables that contain nullable fields.
- Support foreign keys to non-integer ids
2.5.1.3
- fix GHC 7.8 bug when a field name is “type”
2.5.1.2
- fix a bad Eq instance /= definition for Key when mpsGenetric=True
2.5.0.1
- workaround TH bug in GHC 7.10
2.5
- read/write typeclass split
2.1.6
- aeson 0.11
- transformers 0.5
2.1.4
support http-api-data for url serialization
2.1.3.3
By default explicitly use Int64 for foreign key references. This avoids confusion on a 32 bit system.
2.1.3.1
Support foreign key references to composite primary keys
2.1.0.1
Support for monad-control 1.0