Skip to content

Commit

Permalink
Add new functions for multi tenancy in lib/version.ex
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamingechoes committed Aug 1, 2017
1 parent 8a2dfb5 commit a1ffd44
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ defmodule PaperTrail.Version do
def count do
from(version in __MODULE__, select: count(version.id)) |> PaperTrail.RepoClient.repo.one
end
def count(options) do
from(version in __MODULE__, select: count(version.id))
|> Ecto.Queryable.to_query()
|> Map.put(:prefix, options[:prefix])
|> PaperTrail.RepoClient.repo.one
end

@doc """
Returns the first version record in the database by :inserted_at
Expand All @@ -45,6 +51,12 @@ defmodule PaperTrail.Version do
from(record in __MODULE__, limit: 1, order_by: [asc: :inserted_at])
|> PaperTrail.RepoClient.repo.one
end
def first(options) do
from(record in __MODULE__, limit: 1, order_by: [asc: :inserted_at])
|> Ecto.Queryable.to_query()
|> Map.put(:prefix, options[:prefix])
|> PaperTrail.RepoClient.repo.one
end

@doc """
Returns the last version record in the database by :inserted_at
Expand All @@ -53,4 +65,10 @@ defmodule PaperTrail.Version do
from(record in __MODULE__, limit: 1, order_by: [desc: :inserted_at])
|> PaperTrail.RepoClient.repo.one
end
def last(options) do
from(record in __MODULE__, limit: 1, order_by: [desc: :inserted_at])
|> Ecto.Queryable.to_query()
|> Map.put(:prefix, options[:prefix])
|> PaperTrail.RepoClient.repo.one
end
end

0 comments on commit a1ffd44

Please sign in to comment.