diesel-softdelete 0.1.0

Soft-delete support for the Diesel ORM
Documentation
  • Coverage
  • 54.17%
    13 out of 24 items documented1 out of 12 items with examples
  • Size
  • Source code size: 45.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.86 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 24s Average build duration of successful builds.
  • all releases: 24s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Tuetuopay/diesel-softdelete
    0 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Tuetuopay

diesel-softdelete

Add soft-delete integration to the Diesel query builder.

Soft deletion is a practice where a database entry is not actually deleted, but flagged as deleted. This often takes the form of a deleted boolean flag. However this implies always filtering on this flag in your queries, which is both cumbersome and error prone: always filtering on the flag is repetitive, can be forgotten and can lead to incorrect queries in e.g. joins.

The main additions of this library are to the query builder, with new operations:

Usage

Your model needs to have a deleted boolean column. Then, use the soft_delete macro to implement the SoftDelete trait on the table. And that's it! The soft_find and other functions are ready to be used in place of the regular find etc macros once the prelude is imported.

Example

use diesel_softdelete::prelude::*;

table! {
    user (id) {
        id -> Integer,
        name -> Text,
        deleted -> Bool,
    }
}
soft_delete!(user);

conn.batch_execute("
    create table user(
        id integer primary key,
        name text not null,
        deleted bool not null default false
    );
    insert into user(id, name, deleted) values (1, 'Alice', false), (2, 'Bob', true);
")?;

let name = user::table.soft_find(1).select(user::name).first::<String>(&conn).optional()?;
assert_eq!(name, Some("Alice".to_owned()));
let name = user::table.soft_find(2).select(user::name).first::<String>(&conn).optional()?;
assert_eq!(name, None);

License: MIT OR Apache-2.0