Txbox v0.2.2 Txbox.Transactions View Source
Collection of functions for composing Ecto queries.
The functions in this module can be broadly split into two types, expressions and queries.
Expressions
Expression functions can be used to compose queries following the Elixir pipeline syntax.
iex> Tx
...> |> Transactions.confirmed(true)
...> |> Transactions.tagged(["space", "photos"])
%Ecto.Query{}
Queries
Query functions interface with the repo and either create or return records from the repo.
iex> Transactions.list_tx()
[%Tx{}, ...]
Link to this section Summary
Expressions
Query by the given channel name.
Query by the transaction confirmation status.
Query by the given query map.
Search by the given term.
Query by the given tag or list of tags.
Queries
Creates a transaction from the given params.
Deletes the given transaction from the repo.
Get a transaction by it's internal ID or TXID.
Returns a list of transactions.
Returns a list of transactions that must be pushed or have their status confirmed by mAPI.
Returns a list of transactions filtered by the given search term.
Updates the transaction with the given params.
Updates the given transaction's state.
Updates the given transaction's state, and stores the mAPI response.
Link to this section Expressions
Specs
channel(Ecto.Queryable.t(), binary()) :: Ecto.Queryable.t()
Query by the given channel name.
Specs
confirmed(Ecto.Queryable.t(), boolean()) :: Ecto.Queryable.t()
Query by the transaction confirmation status.
Specs
query(Ecto.Queryable.t(), map()) :: Ecto.Queryable.t()
Query by the given query map.
Specs
search(Ecto.Queryable.t(), String.t()) :: Ecto.Queryable.t()
Search by the given term.
Specs
tagged(Ecto.Queryable.t(), list() | String.t()) :: Ecto.Queryable.t()
Query by the given tag or list of tags.
Optionally tags can be specified as a comma seperated string
Link to this section Queries
Specs
create_tx(map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Creates a transaction from the given params.
Returns an :ok
/ :error
tuple response.
Examples
iex> {:ok, tx} = Transactions.create_tx(%{
...> txid: "6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110",
...> channel: "mychannel"
...> })
Specs
delete_tx(Ecto.Schema.t()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Deletes the given transaction from the repo.
Returns an :ok
/ :error
tuple response.
Examples
iex> {:ok, tx} = Transactions.get_tx("6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110")
...> |> Transactions.delete_tx
Specs
get_tx(Ecto.Queryable.t(), binary()) :: Ecto.Schema.t() | nil
Get a transaction by it's internal ID or TXID.
Can optionally pass a Ecto.Queryable.t
as the first argument to compose
queries.
Examples
# Find a tx by it's Txbox uuid
iex> tx = Transactions.find_tx "e9d356cf-47e9-47c3-bfc8-c12673877302"
# Composed query, found by txid
iex> tx = Transactions.channel("mychannel)
...> |> Transactions.confirmed(true)
...> |> Transactions.find_tx("6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110")
Specs
list_tx(Ecto.Queryable.t(), map()) :: [Ecto.Schema.t()]
Returns a list of transactions.
Can optionally pass a Ecto.Queryable.t
as the first argument to compose
queries. If a map of query options is given as a secndon argument, the query
is filtered by those arguments.
Examples
iex> txns = Transactions.channel("mychannel)
...> |> Transactions.confirmed(true)
...> |> Transactions.list_tx
Specs
list_tx_for_mapi(keyword()) :: [Ecto.Schema.t()]
Returns a list of transactions that must be pushed or have their status confirmed by mAPI.
This is used internally by Txbox.Mapi.Queue
to fetch transactions for
automatic processing.
Options
The accepted options are:
:max_status_attempts
- How many times to poll mAPI for confirmation status. Defaults to20
.:retry_status_after
- Number of seconds before polling mAPI for confirmation status. Defaults to300
(5 minutes).
Specs
search_tx(Ecto.Queryable.t(), String.t()) :: [Ecto.Schema.t()]
Returns a list of transactions filtered by the given search term.
Performs a full text search on the transactions' metadata. Can optionally pass
a Ecto.Queryable.t
as the first argument to compose queries.
Examples
iex> {:ok, txns} = Transactions.search_tx("unwriter bitpic")
Specs
update_tx(Ecto.Schema.t(), map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Updates the transaction with the given params.
Returns an :ok
/ :error
tuple response.
Examples
iex> {:ok, tx} = Transactions.update_tx(tx, %{
...> meta: %{
...> title: "Hubble Ultra-Deep Field"
...> }
...> })
Specs
update_tx_state(Ecto.Schema.t(), String.t()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Updates the given transaction's state.
Returns an :ok
/ :error
tuple response.
Examples
iex> {:ok, tx} = Transactions.update_tx_state(tx, "pushed")
Specs
update_tx_state(Ecto.Schema.t(), String.t(), Manic.JSONEnvelope.t() | map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()} | {:error, %{required(atom()) => Ecto.Changeset.t()}}
Updates the given transaction's state, and stores the mAPI response.
Returns an :ok
/ :error
tuple response.
Examples
iex> {:ok, tx} = Transactions.update_tx_state(tx, "pushed", mapi_response)
Link to this section Functions
Specs
repo() :: module()
Returns the application's configured Repo.
Ensure your application's Repo is configured in config.exs
:
config :txbox, repo: MyApp.Repo