Implement Soft Deletes
Prerequisites
schema.table :users do
primary :id, Int64, auto_increment: true
column :name, String
column :deleted_at, Time, null: true
timestamps
end
schema.users.create!Enable Soft Deletes
struct User
include CQL::ActiveRecord::Model(Int64)
include CQL::ActiveRecord::SoftDeletable
db_context MyDB, :users
property id : Int64?
property name : String
property created_at : Time?
property updated_at : Time?
# deleted_at is handled automatically
def initialize(@name : String)
end
endSoft Delete Records
Delete a Single Record
Delete by ID
Delete by Attributes
Delete All Records
Restore Records
Restore a Single Record
Restore by ID
Restore All Deleted Records
Query Records
Include Deleted Records
Query Only Deleted Records
Permanently Delete
Add Index for Performance
Cleanup Old Records
Cascade Soft Deletes
Verify It Works
Related
Last updated
Was this helpful?