Skip to content

Commit 78de457

Browse files
authored
delete all only accepts query chain (#53)
* delete all only accepts query chain * remove unnecessary close before return
1 parent 5fb30e3 commit 78de457

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

docs/instrumentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instrumentation
22

3-
REL provides hooks that can be used to log or instrument your queries. It can be used for the this operations:
3+
REL provides hooks that can be used to log or instrument your queries. This is the list for available operations:
44

55
- `rel-aggregate`
66
- `rel-count`

docs/query.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func Iteration(ctx context.Context, repo rel.Repository) error {
3434
}
3535

3636
// handle error
37-
iter.Close()
3837
return err
3938
}
4039

reltest/delete_all.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ func (eda *DeleteAll) Unsafe() {
1616
}
1717

1818
// ExpectDeleteAll to be called with given field and queries.
19-
func ExpectDeleteAll(r *Repository, queriers []rel.Querier) *DeleteAll {
19+
func ExpectDeleteAll(r *Repository, query rel.Query) *DeleteAll {
2020
eda := &DeleteAll{
2121
Expect: newExpect(r, "DeleteAll",
22-
[]interface{}{queriers},
22+
[]interface{}{query},
2323
[]interface{}{nil},
2424
),
2525
}
2626

2727
// validation
2828
eda.Run(func(args mock.Arguments) {
29-
query := rel.Build("", args[0].([]rel.Querier)...)
29+
query := args[0].(rel.Query)
3030

3131
if query.Table == "" {
3232
panic("reltest: cannot call DeleteAll without specifying table name. use rel.From(tableName)")

reltest/delete_all_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ func TestDeleteAll_error(t *testing.T) {
4444

4545
func TestDeleteAll_noTable(t *testing.T) {
4646
var (
47-
repo = New()
47+
repo = New()
48+
query = rel.Where(where.Eq("id", 1))
4849
)
4950

50-
repo.ExpectDeleteAll()
51+
repo.ExpectDeleteAll(query)
5152
assert.Panics(t, func() {
52-
repo.MustDeleteAll(context.TODO())
53+
repo.MustDeleteAll(context.TODO(), query)
5354
})
5455
repo.AssertExpectations(t)
5556
}

reltest/repository.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,19 @@ func (r *Repository) ExpectDelete() *Delete {
213213
return ExpectDelete(r)
214214
}
215215

216-
// DeleteAll provides a mock function with given fields: queriers
217-
func (r *Repository) DeleteAll(ctx context.Context, queriers ...rel.Querier) error {
218-
return r.mock.Called(queriers).Error(0)
216+
// DeleteAll provides a mock function with given fields: query
217+
func (r *Repository) DeleteAll(ctx context.Context, query rel.Query) error {
218+
return r.mock.Called(query).Error(0)
219219
}
220220

221-
// MustDeleteAll provides a mock function with given fields: queriers
222-
func (r *Repository) MustDeleteAll(ctx context.Context, queriers ...rel.Querier) {
223-
must(r.DeleteAll(ctx, queriers...))
221+
// MustDeleteAll provides a mock function with given fields: query
222+
func (r *Repository) MustDeleteAll(ctx context.Context, query rel.Query) {
223+
must(r.DeleteAll(ctx, query))
224224
}
225225

226226
// ExpectDeleteAll apply mocks and expectations for DeleteAll
227-
func (r *Repository) ExpectDeleteAll(queriers ...rel.Querier) *DeleteAll {
228-
return ExpectDeleteAll(r, queriers)
227+
func (r *Repository) ExpectDeleteAll(query rel.Query) *DeleteAll {
228+
return ExpectDeleteAll(r, query)
229229
}
230230

231231
// Preload provides a mock function with given fields: records, field, queriers

repository.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ type Repository interface {
3333
MustUpdate(ctx context.Context, record interface{}, modifiers ...Modifier)
3434
Delete(ctx context.Context, record interface{}) error
3535
MustDelete(ctx context.Context, record interface{})
36-
DeleteAll(ctx context.Context, queriers ...Querier) error
37-
MustDeleteAll(ctx context.Context, queriers ...Querier)
36+
DeleteAll(ctx context.Context, query Query) error
37+
MustDeleteAll(ctx context.Context, query Query)
3838
Preload(ctx context.Context, records interface{}, field string, queriers ...Querier) error
3939
MustPreload(ctx context.Context, records interface{}, field string, queriers ...Querier)
4040
Transaction(ctx context.Context, fn func(Repository) error) error
@@ -664,19 +664,15 @@ func (r repository) MustDelete(ctx context.Context, record interface{}) {
664664
must(r.Delete(ctx, record))
665665
}
666666

667-
func (r repository) DeleteAll(ctx context.Context, queriers ...Querier) error {
667+
func (r repository) DeleteAll(ctx context.Context, query Query) error {
668668
finish := r.instrument(ctx, "rel-delete-all", "deleting multiple records")
669669
defer finish(nil)
670670

671-
var (
672-
q = Build("", queriers...)
673-
)
674-
675-
return r.deleteAll(ctx, Invalid, q)
671+
return r.deleteAll(ctx, Invalid, query)
676672
}
677673

678-
func (r repository) MustDeleteAll(ctx context.Context, queriers ...Querier) {
679-
must(r.DeleteAll(ctx, queriers...))
674+
func (r repository) MustDeleteAll(ctx context.Context, query Query) {
675+
must(r.DeleteAll(ctx, query))
680676
}
681677

682678
func (r repository) deleteAll(ctx context.Context, flag DocumentFlag, query Query) error {

0 commit comments

Comments
 (0)