core icon indicating copy to clipboard operation
core copied to clipboard

Add ability to update and delete many entries by criteria

Open dstpierre opened this issue 3 years ago • 5 comments

This will require 2 new database endpoints.

This should take the same query logic as the query function in db.go:167 and use the UpdateMany and DeleteMany functions respectively to update or delete more than one entries based on a filter criteria.

dstpierre avatar Jan 24 '22 10:01 dstpierre

Hey, I want to work on this issue;

szymonnogiec avatar Jul 20 '22 19:07 szymonnogiec

hey @szymonnogiec great. I just read the description, this issue was created prior to having the Persister interface, so let me give an updated guide line here:

Starting from the database sub-packages, you'd have 3 implementation to do, the postgresql, mongo, and memory.

I'd start by implementing the memory one by creating a test and your implementation.

You may test only the memory implementation with make test-mem at the project root.

I'd create two new functions in the base.go file UpdateDocuments and DeleteDocuments matching their non pluralized counter part.

Look at how the QueryDocuments function uses criteria to be a bit inspired, you may look at the TestQueryDocuments function in memory/base_test.go to start writing the TestUpdateDocuments and TestDeleteDocuments tests.

Once you have a working implementation, you might want to add those two function in the internal/persister.go Persister interface and go write the implementation and tests for both postgresql and mongo packages.

The last step will be to modify the update and delete endpoints of the API to handle receiving criteria.

You'll noticed in the db.go:26 the following:

} else if r.Method == http.MethodPut {
  database.update(w, r)
} else if r.Method == http.MethodDelete {
  database.del(w, r)
}

For the update, one simple idea to handle the criteria would be to have a query string parameter in the URL and if present call a new handler that will be able to accept a more complex data object for instance:

{
  "criteria": [],
  "update": {}
}

Where the criteria is the [][]interface{} as seen in the query function of db.go:152. The code that parses the criteria / filters should be extracted from there since it will be re-used by the query function and the two new function that you'll be creating.

Those are just suggestions, feel free to explore and use different ways etc.

Let me know if you have any questions.

dstpierre avatar Jul 21 '22 09:07 dstpierre

Hello! @dstpierre @szymonnogiec don't you mind If I'll take a look as well?

rostikts avatar Aug 10 '22 13:08 rostikts

Hey @rostikts it's awesome you want to work on this. @szymonnogiec started a couple of weeks ago, maybe you could reach them and see if there's way to collaborate on this. The issue is kind of big so I suppose it could be broken down into smaller tasks.

If you're not on Discord - join link yet, I'd suggest you join us there

Let me know how I can help with anything.

dstpierre avatar Aug 10 '22 19:08 dstpierre

Hey @rostikts - @szymonnogiec replied in Discord and this issue could be split into two. One of you take the update part and the other the deletion part.

dstpierre avatar Aug 10 '22 19:08 dstpierre

@szymonnogiec hey how things are going? Can I help with anything?

For the delete part, you may take a look at @rostikts changes for the update and reuse a similar approach / reuse the filtering codee.

Let us know if you have any question, I'd be happy to help you get started and/or unblock for this :wave:

dstpierre avatar Sep 24 '22 11:09 dstpierre

Hey @szymonnogiec last time you confirmed via Discord that you'd still want to tackle this one. Are you still interested? I'm planning a new release and I'd like that one to be part of the next version.

Let me know where things are please, thanks.

dstpierre avatar Dec 11 '22 13:12 dstpierre

implemented the remaining bulk delete in #79 completing this bulk update/delete feature.

dstpierre avatar May 10 '23 17:05 dstpierre