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
F2741660: D2094.id.diff
Thu, Mar 28, 01:37
F2739135: D2094.id5288.diff
Wed, Mar 27, 12:59
F2738595: D2094.id5289.diff
Wed, Mar 27, 09:17
Unknown Object (File)
Wed, Mar 27, 08:16
Unknown Object (File)
Fri, Mar 22, 11:37
Unknown Object (File)
Fri, Mar 22, 11:02
Unknown Object (File)
Sun, Mar 17, 20:12
Unknown Object (File)
Sun, Mar 17, 06:28
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 Not Applicable
Unit
Tests Not Applicable

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.