HomeDevCentral

Allow to craft a JSON response for DELETE SQL queries

Description

Allow to craft a JSON response for DELETE SQL queries

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()
}

Reviewers: dereckson

Reviewed By: dereckson

Differential Revision: https://devcentral.nasqueron.org/D2094

Details

Provenance
derecksonAuthored on Nov 9 2019, 05:23
derecksonPushed on Nov 12 2019, 02:50
Reviewer
dereckson
Differential Revision
D2094: Allow to craft a JSON response for DELETE SQL queries
Parents
rLF500f6bb23e96: Fix PostgreSQL installation instructions
Branches
Unknown
Tags
Unknown
References
tag: v0.7.0