Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamtolipov committed Oct 28, 2018
1 parent 821b897 commit 4cc2cc0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
73 changes: 37 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i
# {:ok,
# %{model: %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">,
# title: "Word on the street is Elixir got its own database versioning library",
# content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 21:42:38>},
# content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 21:42:38]},
# version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "insert", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# event: "insert", id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# item_changes: %{title: "Word on the street is Elixir got its own database versioning library",
# content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 21:42:38>},
# content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 21:42:38]},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}}}

# => on error(it matches Repo.insert/2):
Expand All @@ -45,10 +45,10 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i
# {:ok,
# %{model: %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">,
# title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!",
# id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 22:00:59>},
# id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 22:00:59]},
# version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 22:00:59>,
# event: "update", id: 2, inserted_at: ~N[2016-09-15 22:00:59],
# item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!"},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil
# meta: nil}}}
Expand All @@ -61,7 +61,7 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i

PaperTrail.get_version(post)
# %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 22:00:59>,
# event: "update", id: 2, inserted_at: ~N[2016-09-15 22:00:59],
# item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!"},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}}}

Expand All @@ -72,13 +72,13 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i
# {:ok,
# %{model: %Post{__meta__: #Ecto.Schema.Metadata<:deleted, "posts">,
# title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!",
# id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 22:00:59>},
# id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 22:00:59]},
# version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>,
# event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12],
# item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!",
# id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 22:00:59>},
# id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 22:00:59]},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}}}

Repo.aggregate(Post, :count, :id) # => 0
Expand All @@ -87,7 +87,7 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i

PaperTrail.Version.last() # returns the last version in the db by inserted_at
# %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>,
# event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12],
# item_changes: %{"title" => "Elixir matures fast", content: "Future is already here, Elixir is the next step!", "id" => 1,
# "inserted_at" => "2016-09-15T21:42:38",
# "updated_at" => "2016-09-15T22:00:59"},
Expand All @@ -105,6 +105,7 @@ The library source code is minimal and well tested. It is suggested to read the
```elixir
def deps do
[{:paper_trail, "~> 0.8"}]
# if you want to use PaperTrail with Ecto 3.0, use master branch
end
```

Expand Down Expand Up @@ -278,11 +279,11 @@ When you run PaperTrail.insert/2 transaction, ```first_version_id``` and ```curr
company = Company.changeset(%Company{}, %{name: "Acme LLC"}) |> PaperTrail.insert
# {:ok,
# %{model: %Company{__meta__: #Ecto.Schema.Metadata<:loaded, "companies">,
# name: "Acme LLC", founded_in: nil, id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 21:42:38>, first_version_id: 1, current_version_id: 1},
# name: "Acme LLC", founded_in: nil, id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 21:42:38], first_version_id: 1, current_version_id: 1},
# version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "insert", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>,
# item_changes: %{name: "Acme LLC", founded_in: nil, id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>},
# event: "insert", id: 1, inserted_at: ~N[2016-09-15 22:22:12],
# item_changes: %{name: "Acme LLC", founded_in: nil, id: 1, inserted_at: ~N[2016-09-15 21:42:38]},
# originator_id: nil, origin: "unknown", meta: nil}}}
```

Expand All @@ -292,10 +293,10 @@ When you PaperTrail.update/2 a model, ```current_version_id``` gets updated duri
edited_company = Company.changeset(company, %{name: "Acme Inc."}) |> PaperTrail.update(origin: "documentation")
# {:ok,
# %{model: %Company{__meta__: #Ecto.Schema.Metadata<:loaded, "companies">,
# name: "Acme Inc.", founded_in: nil, id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 23:22:12>, first_version_id: 1, current_version_id: 2},
# name: "Acme Inc.", founded_in: nil, id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 23:22:12], first_version_id: 1, current_version_id: 2},
# version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 23:22:12>,
# event: "update", id: 2, inserted_at: ~N[2016-09-15 23:22:12],
# item_changes: %{name: "Acme Inc."}, originator_id: nil, origin: "documentation", meta: nil}}}
```

Expand All @@ -317,18 +318,18 @@ Bang functions assume the operation will always be successful, otherwise functio
# => on success:
# %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">,
# title: "Word on the street is Elixir got its own database versioning library",
# content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 21:42:38>
# content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 21:42:38]
# }
#
# => on error raises: Ecto.InvalidChangesetError !!

inserted_post_version = PaperTrail.get_version(inserted_post)
# %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "insert", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# event: "insert", id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# item_changes: %{title: "Word on the street is Elixir got its own database versioning library",
# content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 21:42:38>},
# content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 21:42:38]},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}

edit_changeset = Post.changeset(inserted_post, %{
Expand All @@ -340,14 +341,14 @@ Bang functions assume the operation will always be successful, otherwise functio
# => on success:
# %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">,
# title: "Elixir matures fast", content: "Future is already here, you deserve to be awesome!",
# id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 22:00:59>}
# id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 22:00:59]}
#
# => on error raises: Ecto.InvalidChangesetError !!

updated_post_version = PaperTrail.get_version(updated_post)
# %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 22:00:59>,
# event: "update", id: 2, inserted_at: ~N[2016-09-15 22:00:59],
# item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!"},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil
# meta: nil}
Expand All @@ -356,17 +357,17 @@ Bang functions assume the operation will always be successful, otherwise functio
# => on success:
# %Post{__meta__: #Ecto.Schema.Metadata<:deleted, "posts">,
# title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!",
# id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 22:00:59>}
# id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 22:00:59]}
#
# => on error raises: Ecto.InvalidChangesetError !!

PaperTrail.get_version(updated_post)
# %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>,
# event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12],
# item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!",
# id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>,
# updated_at: #Ecto.DateTime<2016-09-15 22:00:59>},
# id: 1, inserted_at: ~N[2016-09-15 21:42:38],
# updated_at: ~N[2016-09-15 22:00:59]},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}

Repo.aggregate(Post, :count, :id) # => 0
Expand All @@ -375,7 +376,7 @@ Bang functions assume the operation will always be successful, otherwise functio

PaperTrail.Version.last() # returns the last version in the db by inserted_at
# %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">,
# event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>,
# event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12],
# item_changes: %{"title" => "Elixir matures fast", content: "Future is already here, Elixir is the next step!", "id" => 1,
# "inserted_at" => "2016-09-15T21:42:38",
# "updated_at" => "2016-09-15T22:00:59"},
Expand Down
1 change: 1 addition & 0 deletions example/.iex.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Ecto.Query

0 comments on commit 4cc2cc0

Please sign in to comment.