on be54907 help sign in
rel8/src/Rel8/Expr/Default.hs
35 lines 1.1 kB history raw
1module Rel8.Expr.Default
2 ( unsafeDefault
3 )
4where
6-- base
7import Prelude ()
9-- opaleye
10import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
12-- rel8
13import Rel8.Expr ( Expr )
14import Rel8.Expr.Opaleye ( fromPrimExpr )
17-- | Corresponds to the SQL @DEFAULT@ expression.
18--
19-- This 'Expr' is unsafe for numerous reasons, and should be used with care:
20--
21-- 1. This 'Expr' only makes sense in an @INSERT@ or @UPDATE@ statement.
22--
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
26--
27-- 3. @DEFAULT@ values can not be transformed. For example, the innocuous Rel8
28-- code @unsafeDefault + 1@ will crash, despite type checking.
29--
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.
34unsafeDefault :: Expr a
35unsafeDefault = fromPrimExpr Opaleye.DefaultInsertExpr