mirror of
https://github.com/circuithub/rel8.git
synced 2024-09-11 16:05:41 +03:00
Update src/Rel8/Expr/Default.hs
Co-authored-by: Shane <shane.obrien@circuithub.com>
This commit is contained in:
parent
6950d691ba
commit
12d242c479
@ -66,6 +66,7 @@ library
|
||||
Rel8.Expr.Aggregate
|
||||
Rel8.Expr.Array
|
||||
Rel8.Expr.Bool
|
||||
Rel8.Expr.Default
|
||||
Rel8.Expr.Eq
|
||||
Rel8.Expr.Function
|
||||
Rel8.Expr.Null
|
||||
|
@ -250,14 +250,15 @@ module Rel8
|
||||
, Insert(..)
|
||||
, OnConflict(..)
|
||||
, insert
|
||||
, unsafeDefault
|
||||
|
||||
-- ** @DELETE@
|
||||
, Delete(..)
|
||||
, delete
|
||||
|
||||
-- ** @UPDATE@
|
||||
, update
|
||||
, Update(..)
|
||||
, update
|
||||
|
||||
-- ** @.. RETURNING@
|
||||
, Returning(..)
|
||||
@ -289,6 +290,7 @@ import Rel8.Column.These
|
||||
import Rel8.Expr
|
||||
import Rel8.Expr.Aggregate
|
||||
import Rel8.Expr.Bool
|
||||
import Rel8.Expr.Default
|
||||
import Rel8.Expr.Eq
|
||||
import Rel8.Expr.Function
|
||||
import Rel8.Expr.Null
|
||||
|
35
src/Rel8/Expr/Default.hs
Normal file
35
src/Rel8/Expr/Default.hs
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user