@@ -0,0 +1,35 @@
1+module Rel8.Expr.Default
10+import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
13+import Rel8.Expr ( Expr )
14+import Rel8.Expr.Opaleye ( fromPrimExpr )
17+-- | Corresponds to the SQL @DEFAULT@ expression.
19+-- This 'Expr' is unsafe for numerous reasons, and should be used with care:
21+-- 1. This 'Expr' only makes sense in an @INSERT@ or @UPDATE@ statement.
23+-- 2. Rel8 is not able to verify that a particular column actually has a
24+-- @DEFAULT@ value. Trying to use @unsafeDefault@ where there is no default
25+-- will cause a runtime crash
27+-- 3. @DEFAULT@ values can not be transformed. For example, the innocuous Rel8
28+-- code @unsafeDefault + 1@ will crash, despite type checking.
30+-- Given all these caveats, we suggest avoiding the use of default values where
31+-- possible, instead being explicit. A common scenario where default values are
32+-- used is with auto-incrementing identifier columns. In this case, we suggest
33+-- using 'Rel8.nextval' instead.
34+unsafeDefault :: Expr a
35+unsafeDefault = fromPrimExpr Opaleye.DefaultInsertExpr