-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new QueryHelper module into example test support folder
This module contains functions related with models queries for test purposes
- Loading branch information
1 parent
a50177a
commit f2519db
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule QueryHelper do | ||
import Ecto.Query | ||
|
||
# Company related query functions | ||
def company_count(), do: (from company in Company, select: count(company.id)) | ||
def company_count(:multitenant), do: company_count() |> MultiTenantHelper.add_prefix_to_query() | ||
|
||
def first_company(), do: (first(Company, :id) |> preload(:people)) | ||
def first_company(:multitenant), do: first_company() |> MultiTenantHelper.add_prefix_to_query() | ||
|
||
def filter_company(opts), do: (from c in Company, where: c.name == ^opts[:name], limit: ^opts[:limit]) | ||
def filter_company(opts, :multitenant), do: filter_company(opts) |> MultiTenantHelper.add_prefix_to_query() | ||
|
||
# Person related query functions | ||
def person_count(), do: (from person in Person, select: count(person.id)) | ||
def person_count(:multitenant), do: person_count() |> MultiTenantHelper.add_prefix_to_query() | ||
|
||
def first_person(), do: (first(Person, :id) |> preload(:company)) | ||
def first_person(:multitenant), do: first_person() |> MultiTenantHelper.add_prefix_to_query() | ||
|
||
# Version related query functions | ||
def version_count(), do: (from version in PaperTrail.Version, select: count(version.id)) | ||
def version_count(:multitenant), do: version_count() |> MultiTenantHelper.add_prefix_to_query() | ||
end |