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
Unknown Object (File)
Fri, Nov 22, 09:19
Unknown Object (File)
Mon, Nov 18, 03:49
Unknown Object (File)
Mon, Nov 18, 03:49
Unknown Object (File)
Mon, Nov 18, 03:49
Unknown Object (File)
Mon, Nov 18, 02:53
Unknown Object (File)
Mon, Nov 18, 02:52
Unknown Object (File)
Mon, Nov 18, 02:21
Unknown Object (File)
Mon, Nov 18, 02:19
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 3267
Build 3516: 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.