Skip to content

Commit

Permalink
Cockroach delete limit (#697)
Browse files Browse the repository at this point in the history
* DELETE FROM must have LIMIT support

CockroachDB is not able to deal well with massive deletes and their recommended approach is to batch delete statements. Thus, support for LIMIT statement is a must in the adapter.

* Updated tests
  • Loading branch information
jgirtakovskis committed Nov 5, 2023
1 parent 8e61801 commit 5025ae3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions adapter/cockroachdb/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ const (
DELETE
FROM {{.Table | compile}}
{{.Where | compile}}
{{if .Limit}}
LIMIT {{.Limit}}
{{end}}
`
adapterUpdateLayout = `
UPDATE
Expand Down
5 changes: 5 additions & 0 deletions adapter/cockroachdb/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,9 @@ func TestTemplateDelete(t *testing.T) {
`DELETE FROM "artist" WHERE (id > 5)`,
b.DeleteFrom("artist").Where("id > 5").String(),
)

assert.Equal(
`DELETE FROM "artist" WHERE (id > 5) LIMIT 10`,
b.DeleteFrom("artist").Where("id > 5").Limit(10).String(),
)
}

0 comments on commit 5025ae3

Please sign in to comment.