From f2519dbe638f10da9aa470fb892a17856d18d6f3 Mon Sep 17 00:00:00 2001 From: Ivan Gonzalez Date: Tue, 1 Aug 2017 11:08:12 +0200 Subject: [PATCH] Add new QueryHelper module into example test support folder This module contains functions related with models queries for test purposes --- example/test/support/query_helper.exs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 example/test/support/query_helper.exs diff --git a/example/test/support/query_helper.exs b/example/test/support/query_helper.exs new file mode 100644 index 00000000..72a17740 --- /dev/null +++ b/example/test/support/query_helper.exs @@ -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