Sitesx v0.11.0 Sitesx.Q View Source

Ecto Query Helper along with Sitesx.Plug

Link to this section Summary

Functions

To ensure all of dns record, which stores boolean to database

Like a exists query statement

Get a record or create a record then returns a record with result key along with create a CNAME record into DNS Provider when db record created

Find a record from Plug.Conn or subdomain name

Get a sitesx record from model which relates as 1:N between one of model and Sitesx

Link to this section Functions

Link to this function ensure_domains() View Source
ensure_domains() :: :ok

To ensure all of dns record, which stores boolean to database.

Link to this function exists?(queryable) View Source
exists?(queryable :: Ecto.Query.t) :: boolean

Like a exists query statement.

Example

queryable =
  from q in MyApp.Site,
    where: q.name == "subdomain1",

Sitesx.Q.exists?(queryable)
#-> true
Link to this function get_or_create(subdomain, domain \\ []) View Source
get_or_create(subdomain :: Ecto.Query.t, domain :: list) ::
  {:get, term} |
  {:new, term} |
  {:error, String.t | {:error, Error.t}}

Get a record or create a record then returns a record with result key along with create a CNAME record into DNS Provider when db record created.

Example

case Sitesx.Q.get_or_create("subdomain1") do
  {:new, %MyApp.Site{} = site} ->
    dosomething(site)

  {:get, %MyApp.Site{} = site} ->
    site
end
Link to this function site(conn) View Source
site(conn :: Plug.Conn.t) :: Ecto.Query.t | nil
site(name :: String.t) :: Ecto.Query.t | nil

Find a record from Plug.Conn or subdomain name

Example

Sitesx.Q.findstate(conn)
#-> #Ecto.Query<from s in MyApp.Site, where: s.name == ^"subdomain1">

Sitesx.Q.findstate("subdomain1")
#-> #Ecto.Query<from s in MyApp.Site, where: s.name == ^"subdomain1">
Link to this function with_site(queryable, conn) View Source
with_site(queryable :: Ecto.Query.t, conn :: Plug.Conn.t) :: Ecto.Query.t

Get a sitesx record from model which relates as 1:N between one of model and Sitesx

Example

defmodule MyApp.MyController do
  use MyApp.Web, :controller
  plug Sitesx.Plug

  def something(conn, params) do
    entries =
      Entry
      |> Sitesx.Q.with_site(conn)
      |> Repo.paginate(params)

    render conn, "something.html", entries: entries
  end
end