jet/postgres/delete_statement.go

52 lines
1.3 KiB
Go
Raw Normal View History

2019-08-11 09:52:02 +02:00
package postgres
import "source.gleipnir.technology/Gleipnir/jet/internal/jet"
2019-08-11 09:52:02 +02:00
2019-08-17 14:49:35 +02:00
// DeleteStatement is interface for PostgreSQL DELETE statement
2019-08-11 09:52:02 +02:00
type DeleteStatement interface {
jet.SerializerStatement
2019-08-11 09:52:02 +02:00
USING(tables ...ReadableTable) DeleteStatement
2019-08-11 09:52:02 +02:00
WHERE(expression BoolExpression) DeleteStatement
RETURNING(projections ...jet.Projection) DeleteStatement
}
type deleteStatementImpl struct {
2019-08-17 18:32:01 +02:00
jet.SerializerStatement
2019-08-11 09:52:02 +02:00
2022-09-29 13:33:00 +02:00
Delete jet.ClauseDelete
Using jet.ClauseFrom
2019-08-11 09:52:02 +02:00
Where jet.ClauseWhere
Returning jet.ClauseReturning
2019-08-11 09:52:02 +02:00
}
func newDeleteStatement(table WritableTable) DeleteStatement {
newDelete := &deleteStatementImpl{}
newDelete.SerializerStatement = jet.NewStatementImpl(Dialect, jet.DeleteStatementType, newDelete,
&newDelete.Delete,
&newDelete.Using,
&newDelete.Where,
&newDelete.Returning)
2019-08-11 09:52:02 +02:00
2022-09-29 13:33:00 +02:00
newDelete.Delete.Table = table
newDelete.Using.Name = "USING"
2019-08-11 09:52:02 +02:00
newDelete.Where.Mandatory = true
return newDelete
}
func (d *deleteStatementImpl) USING(tables ...ReadableTable) DeleteStatement {
d.Using.Tables = readableTablesToSerializerList(tables)
return d
}
2019-08-11 09:52:02 +02:00
func (d *deleteStatementImpl) WHERE(expression BoolExpression) DeleteStatement {
d.Where.Condition = expression
return d
}
func (d *deleteStatementImpl) RETURNING(projections ...jet.Projection) DeleteStatement {
d.Returning.ProjectionList = projections
2019-08-11 09:52:02 +02:00
return d
}