{-# LANGUAGE
DeriveGeneric
, DerivingStrategies
, FlexibleContexts
, FlexibleInstances
, GADTs
, GeneralizedNewtypeDeriving
, LambdaCase
, MultiParamTypeClasses
, OverloadedStrings
, PatternSynonyms
, QuantifiedConstraints
, RankNTypes
, ScopedTypeVariables
, TypeApplications
, TypeFamilies
, TypeInType
, TypeOperators
, UndecidableInstances
#-}
module Squeal.PostgreSQL.Manipulation.Delete
(
deleteFrom
, deleteFrom_
, UsingClause (..)
) where
import qualified Generics.SOP as SOP
import Squeal.PostgreSQL.Type.Alias
import Squeal.PostgreSQL.Expression.Logic
import Squeal.PostgreSQL.Manipulation
import Squeal.PostgreSQL.Type.List
import Squeal.PostgreSQL.Render
import Squeal.PostgreSQL.Query.From
import Squeal.PostgreSQL.Type.Schema
data UsingClause with db params from where
NoUsing :: UsingClause with db params '[]
Using
:: FromClause '[] with db params from
-> UsingClause with db params from
deleteFrom
:: ( SOP.SListI row
, Has sch db schema
, Has tab schema ('Table table) )
=> QualifiedAlias sch tab
-> UsingClause with db params from
-> Condition 'Ungrouped '[] with db params (tab ::: TableToRow table ': from)
-> ReturningClause with db params '[tab ::: TableToRow table] row
-> Manipulation with db params row
deleteFrom tab using wh returning = UnsafeManipulation $
"DELETE FROM"
<+> renderSQL tab
<> case using of
NoUsing -> ""
Using tables -> " USING" <+> renderSQL tables
<+> "WHERE" <+> renderSQL wh
<> renderSQL returning
deleteFrom_
:: ( Has sch db schema
, Has tab schema ('Table table) )
=> QualifiedAlias sch tab
-> Condition 'Ungrouped '[] with db params '[tab ::: TableToRow table]
-> Manipulation with db params '[]
deleteFrom_ tab wh = deleteFrom tab NoUsing wh (Returning_ Nil)