Skip to content

Commit

Permalink
Add new QueryHelper module into example test support folder
Browse files Browse the repository at this point in the history
This module contains functions related with models queries for test purposes
  • Loading branch information
dreamingechoes committed Aug 1, 2017
1 parent a50177a commit f2519db
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions example/test/support/query_helper.exs
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

0 comments on commit f2519db

Please sign in to comment.