• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Elixir
  • License
    MIT License
  • Created about 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Soft Deletion for Ecto

Build Status Hex.pm License: MIT Coverage Status

EctoSoftDelete

Adds columns, fields, and queries for soft deletion with Ecto.

Documentation

Usage

Migrations

In migrations for schemas to support soft deletion, import Ecto.SoftDelete.Migration. Next, add soft_delete_columns() when creating a table

defmodule MyApp.Repo.Migrations.CreateUser do
  use Ecto.Migration
  import Ecto.SoftDelete.Migration

  def change do
    create table(:users) do
      add :email, :string
      add :password, :string
      timestamps()
      soft_delete_columns()
    end
  end
end

Schemas

Import Ecto.SoftDelete.Schema into your Schema module, then add soft_delete_schema() to your schema

  defmodule User do
    use Ecto.Schema
    import Ecto.SoftDelete.Schema

    schema "users" do
      field :email,           :string
      soft_delete_schema()
    end
  end

Queries

To query for items that have not been deleted, use with_undeleted(query) which will filter out deleted items using the deleted_at column produced by the previous 2 steps

import Ecto.SoftDelete.Query

query = from(u in User, select: u)
|> with_undeleted

results = Repo.all(query)

Repos

To support deletion in repos, just add use Ecto.SoftDelete.Repo to your repo. After that, the functions soft_delete!/1, soft_delete/1 and soft_delete_all/1 will be available for you.

# repo.ex
defmodule Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres
  use Ecto.SoftDelete.Repo
end

# posts.ex
Repo.soft_delete_all(Post)
from(p in Post, where: p.id < 10) |> Repo.soft_delete_all()

post = Repo.get!(Post, 42)
case Repo.soft_delete post do
  {:ok, struct}       -> # Soft deleted with success
  {:error, changeset} -> # Something went wrong
end

post = Repo.get!(Post, 42)
struct = Repo.soft_delete!(post)

Installation

Add to mix.exs:

defp deps do
  [{:ecto_soft_delete, "~> 1.0"}]
end

and do

mix deps.get

Configuration

There are currently no configuration options.

Usage

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/revelrylabs/ecto_soft_delete. Check out CONTRIBUTING.md for more info.

Everyone is welcome to participate in the project. We expect contributors to adhere the Contributor Covenant Code of Conduct (see CODE_OF_CONDUCT.md).

More Repositories

1

elixir-nodejs

An Elixir API for calling Node.js functions
Elixir
169
star
2

elixir_react_render

React SSR Framework for Elixir
Elixir
111
star
3

text_chunker_ex

A library for semantically coherent text chunking
Elixir
65
star
4

harmonium

An opinionated React component framework for teams that move fast.
JavaScript
34
star
5

revelry_phoenix_app_template

App Template for Revelry Phoenix
Elixir
32
star
6

ecto_explain

Elixir
25
star
7

elixir-stellar-client

Elixir Client for Stellar
Elixir
21
star
8

sassy-npm-importer

Import SASS from npm via a customizable prefix.
JavaScript
18
star
9

adminable

Allows creating admin interfaces through implementing the `Adminable` behaviour
Elixir
15
star
10

hubkit

Hubkit provides methods for querying the github API at a higher level than making individual API calls. Think of it like an ORM for the github API.
Ruby
15
star
11

slax

Elixir Slack slash command handler
Elixir
13
star
12

ecto_filters

Elixir
12
star
13

liveview_web3

Elixir
10
star
14

phoenix_harmonium

Phoenix Framework view helpers for Harmonium-style components (https://harmonium.revelry.co)
Elixir
10
star
15

react-uniqueid

Provider component and connect function for generating unique identifiers in React.
JavaScript
8
star
16

storybot-ai

AI Generated User Stories from your CLI
JavaScript
6
star
17

aws_parameter_store_config_provider

Elixir
5
star
18

ecto_sort

Elixir
5
star
19

transmit

Plug for handling the creation of presigned urls for direct client-side uploading
Elixir
4
star
20

zoom-archive-scraper

Some example elixir code for scraping Zoom's Recording Management section for old recordings
Elixir
4
star
21

exdr

Elixir
4
star
22

bn-mobile-react

BigNeon React Native Repo
JavaScript
2
star
23

velocity_calculator

Elixir
2
star
24

tenk

An unofficial Ruby API wrapper for working with the 10k Plans (http://www.10000ft.com/).
Ruby
2
star
25

moondog-engine

An opinionated bootstrapper for Goodâ„¢ Kubernetes clusters.
Shell
2
star
26

metairie

Set of modules for monitoring Elixir/Phoenix apps and sending them to a statsD compatible client
Elixir
2
star
27

Harmonium-RN

Reactive Native Harmonium Styles
JavaScript
1
star
28

react-native-duration-picker

A duration picker component for React Native
JavaScript
1
star
29

revelry-koans

Elixir
1
star
30

journal

Versioned key/value store with multiple backend support
Elixir
1
star
31

ex_selfie

Provides a single way to access both a struct's fields and its associated module's functions.
Elixir
1
star
32

slush-revelry

A generator for Revelry Node.js apps that use React, Redux, and more.
JavaScript
1
star
33

tracing

Contact Tracing Prototype
1
star
34

helm-charts

Our public helm charts
Smarty
1
star
35

review_bot_operator

Elixir
1
star