jet/mysql/delete_statement.go

49 lines
1.2 KiB
Go
Raw Normal View History

2019-08-11 12:13:59 +02:00
package mysql
import "github.com/go-jet/jet/internal/jet"
type DeleteStatement interface {
2019-08-15 13:54:05 +02:00
Statement
2019-08-11 12:13:59 +02:00
WHERE(expression BoolExpression) DeleteStatement
ORDER_BY(orderByClauses ...jet.OrderByClause) DeleteStatement
LIMIT(limit int64) DeleteStatement
2019-08-11 12:13:59 +02:00
}
type deleteStatementImpl struct {
jet.StatementImpl
Delete jet.ClauseStatementBegin
Where jet.ClauseWhere
OrderBy jet.ClauseOrderBy
Limit jet.ClauseLimit
2019-08-11 12:13:59 +02:00
}
func newDeleteStatement(table Table) DeleteStatement {
newDelete := &deleteStatementImpl{}
newDelete.StatementImpl = jet.NewStatementImpl(Dialect, jet.DeleteStatementType, newDelete, &newDelete.Delete,
&newDelete.Where, &newDelete.OrderBy, &newDelete.Limit)
2019-08-11 12:13:59 +02:00
newDelete.Delete.Name = "DELETE FROM"
newDelete.Delete.Tables = append(newDelete.Delete.Tables, table)
newDelete.Where.Mandatory = true
newDelete.Limit.Count = -1
2019-08-11 12:13:59 +02:00
return newDelete
}
func (d *deleteStatementImpl) WHERE(expression BoolExpression) DeleteStatement {
2019-08-11 12:13:59 +02:00
d.Where.Condition = expression
return d
}
func (s *deleteStatementImpl) ORDER_BY(orderByClauses ...jet.OrderByClause) DeleteStatement {
s.OrderBy.List = orderByClauses
return s
}
func (s *deleteStatementImpl) LIMIT(limit int64) DeleteStatement {
s.Limit.Count = limit
return s
}