-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Rel8.Expr.Default | ||
( unsafeDefault | ||
) | ||
where | ||
|
||
-- base | ||
import Prelude () | ||
|
||
-- opaleye | ||
import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye | ||
|
||
-- rel8 | ||
import Rel8.Expr ( Expr ) | ||
import Rel8.Expr.Opaleye ( fromPrimExpr ) | ||
|
||
|
||
-- | Corresponds to the SQL @DEFAULT@ expression. | ||
-- | ||
-- This 'Expr' is unsafe for numerous reasons, and should be used with care: | ||
-- | ||
-- 1. This 'Expr' only makes sense in an @INSERT@ or @UPDATE@ statement. | ||
-- | ||
-- 2. Rel8 is not able to verify that a particular column actually has a | ||
-- @DEFAULT@ value. Trying to use @unsafeDefault@ where there is no default | ||
-- will cause a runtime crash | ||
-- | ||
-- 3. @DEFAULT@ values can not be transformed. For example, the innocuous Rel8 | ||
-- code @unsafeDefault + 1@ will crash, despite type checking. | ||
-- | ||
-- Given all these caveats, we suggest avoiding the use of default values where | ||
-- possible, instead being explicit. A common scenario where default values are | ||
-- used is with auto-incrementing identifier columns. In this case, we suggest | ||
-- using 'Rel8.nextval' instead. | ||
unsafeDefault :: Expr a | ||
unsafeDefault = fromPrimExpr Opaleye.DefaultInsertExpr |