No commit activity in last 3 years
No release in over 3 years
A simple Sequel plugin that provides soft delete capabilities.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Build Status

Sequel SoftDestroy plugin

Sequel::Plugins::SoftDestroy is a simple and opinionated Sequel plugin that provides soft delete capabilities.

This gem avoids dealing with Sequel internals and relies on models having a deleted_at column. When a model is soft deleted, a timestamp will be added to the deleted_at field, which marks it as deleted and also stores the UTC time in which the model was deleted. This is useful if any unique constraints have to be observed in your application.

Usage

class Foo < Sequel::Model
  plugin :soft_destroy
end

When you want to soft delete a model, just call soft_destroy on it:

foo = Foo.create(name: "foo")

foo.deleted? #=> false

foo.soft_destroy

foo.deleted? #=> true

This library also provides convenience methods to filter out deleted items:

foo_1 = Foo.create(name: "foo 2")
foo_2 = Foo.create(name: "foo 1")

foo_1.soft_destroy

Foo[foo_1.id] #=> nil

Foo.filter_deleted.all #=> [foo_2]

If you ever need to recover a deleted mode, just call recover:

foo = Foo.create(name: "foo")

foo.deleted? #=> false

foo.soft_destroy

foo.deleted? #=> true

foo.recover

foo.deleted? #=> false