Page MenuHomeDevCentral

Allow to craft a JSON response for DELETE SQL queries
ClosedPublic

Authored by dereckson on Nov 9 2019, 05:32.
Tags
None
Referenced Files
F7927401: D2094.diff
Mon, May 5, 09:36
Unknown Object (File)
Sat, May 3, 07:32
Unknown Object (File)
Mon, Apr 28, 08:05
Unknown Object (File)
Sun, Apr 20, 20:41
Unknown Object (File)
Mon, Apr 14, 19:02
Unknown Object (File)
Mon, Apr 14, 18:56
Unknown Object (File)
Mon, Apr 14, 17:39
Unknown Object (File)
Sun, Apr 13, 09:10
Subscribers
None

Details

Summary

When a DELETE statement is executed, most SQL databases
return the number of rows deleted on success.

For a CRUD API, no row deleted means the object isn't found
while 1 row deleted means success. Any other result (more
than one row or a SQL error) is a failure.

This change implements such logic in the ApiDeleteResponse
trait, implemented for QueryResult<usize>.

Test Plan

An example of use is:

pub fn delete_deck(connection: DatabaseConnection, deck_id: i32) -> ApiJsonResponse<()> {
    diesel::delete(
        decks
            .filter(id.eq(&deck_id))
    )
        .execute(&*connection)
        .into_delete_json_response()
}

Diff Detail

Repository
rLF Limiting Factor
Lint
Lint Passed
Unit
No Test Coverage
Branch
quux
Build Status
Buildable 3266
Build 3515: arc lint + arc unit

Event Timeline

dereckson created this revision.
dereckson edited the summary of this revision. (Show Details)
dereckson edited the test plan for this revision. (Show Details)
dereckson added a reviewer: dereckson.
This revision is now accepted and ready to land.Nov 12 2019, 02:46
This revision was automatically updated to reflect the committed changes.