builder_delete.go 567 B

123456789101112131415161718192021222324252627
  1. // Copyright 2016 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. import (
  6. "fmt"
  7. )
  8. // Delete creates a delete Builder
  9. func Delete(conds ...Cond) *Builder {
  10. builder := &Builder{cond: NewCond()}
  11. return builder.Delete(conds...)
  12. }
  13. func (b *Builder) deleteWriteTo(w Writer) error {
  14. if len(b.from) <= 0 {
  15. return ErrNoTableName
  16. }
  17. if _, err := fmt.Fprintf(w, "DELETE FROM %s WHERE ", b.from); err != nil {
  18. return err
  19. }
  20. return b.cond.WriteTo(w)
  21. }