on package:esqueleto

An ON clause, useful to describe how two tables are related. Cross joins and tuple-joins do not need an on clause, but InnerJoin and the various outer joins do. Database.Esqueleto.Experimental in version 4.0.0.0 of the library. The Experimental module has a dramatically improved means for introducing tables and entities that provides more power and less potential for runtime errors. If you don't include an on clause (or include too many!) then a runtime exception will be thrown. As an example, consider this simple join:
select $
from $ \(foo `InnerJoin` bar) -> do
on (foo ^. FooId ==. bar ^. BarFooId)
...
We need to specify the clause for joining the two columns together. If we had this:
select $
from $ \(foo `CrossJoin` bar) -> do
...
Then we can safely omit the on clause, because the cross join will make pairs of all records possible. You can do multiple on clauses in a query. This query joins three tables, and has two on clauses:
select $
from $ \(foo `InnerJoin` bar `InnerJoin` baz) -> do
on (baz ^. BazId ==. bar ^. BarBazId)
on (foo ^. FooId ==. bar ^. BarFooId)
...
Old versions of esqueleto required that you provide the on clauses in reverse order. This restriction has been lifted - you can now provide on clauses in any order, and the SQL should work itself out. The above query is now totally equivalent to this:
select $
from $ \(foo `InnerJoin` bar `InnerJoin` baz) -> do
on (foo ^. FooId ==. bar ^. BarFooId)
on (baz ^. BazId ==. bar ^. BarBazId)
...
An ON clause that describes how two tables are related. This should be used as an infix operator after a JOIN. For example,
select $
from $ table @Person
`innerJoin` table @BlogPost
`on` (\(p :& bP) ->
p ^. PersonId ==. bP ^. BlogPostAuthorId)
Given a proxy for a PersistEntity record, this returns the sole UniqueDef for that entity.
Return the single unique key for a record.

Example usage

We use shcema-1 and dataset-1 here.
onlySimonConst :: MonadIO m => ReaderT SqlBackend m (Unique User)
onlySimonConst = onlyUnique $ User "Simon" 999
mSimonConst <- onlySimonConst
mSimonConst would be Simon's uniqueness constraint. Note that onlyUnique doesn't work if there're more than two constraints. It will fail with a type error instead.
Exception thrown whenever on is used to create an ON clause but no matching JOIN is found.
This class is used to ensure that upsert is only called on records that have a single Unique key. The quasiquoter automatically generates working instances for appropriate records, and generates TypeError instances for records that have 0 or multiple unique keys.
This class is used to ensure that functions requring at least one unique key are not called with records that have 0 unique keys. The quasiquoter automatically writes working instances for appropriate entities, and generates TypeError instances for records that have 0 unique keys.
An action that might happen on a deletion or update on a foreign key change.
A list of SQL operations, marked with a safety flag. If the Bool is True, then the operation is *unsafe* - it might be destructive, or otherwise not idempotent. If the Bool is False, then the operation is *safe*, and can be run repeatedly without issues.
Values to configure a pool of database connections. See Data.Pool for details.
A ConstraintNameDB represents the datastore-side name that persistent will use for a constraint.
An ConstraintNameHS represents the Haskell-side name that persistent will use for a constraint.
Phantom type used by distinctOn and don.
Optional module and name.
Specify a name for the constraint on the foreign key reference for this table.
Post
title    Text

Comment
postId   PostId constraint="my_cool_constraint_name"