### Money.Ecto.Map.Type.init/1 Source: https://context7_llms Callback implementation for Ecto.ParameterizedType.init/1. ```APIDOC ## Money.Ecto.Map.Type.init/1 ### Description Callback implementation for `Ecto.ParameterizedType.init/1`. ### Method `init/1` (function) ### Endpoint `Money.Ecto.Map.Type.init/1` ``` -------------------------------- ### Use Money.Ecto.Query.API with Custom Adapter Source: https://context7_llms This snippet demonstrates how to configure the Money.Ecto.Query.API behaviour to use a custom adapter module. This is useful when you have alternative implementations or need to support databases other than the default Postgres composite type. The custom adapter must comply with the Money.Ecto.Query.API behaviour. ```elixir use Money.Ecto.Query.API, adapter: MyAdapterModule ``` -------------------------------- ### Money.Ecto.Map.Type.load/3 Source: https://context7_llms Callback implementation for Ecto.ParameterizedType.load/3. ```APIDOC ## Money.Ecto.Map.Type.load/3 ### Description Callback implementation for `Ecto.ParameterizedType.load/3`. ### Method `load/3` (function) ### Endpoint `Money.Ecto.Map.Type.load/3` ``` -------------------------------- ### Money.Ecto.Map.Type.dump/3 Source: https://context7_llms Callback implementation for Ecto.ParameterizedType.dump/3. ```APIDOC ## Money.Ecto.Map.Type.dump/3 ### Description Callback implementation for `Ecto.ParameterizedType.dump/3`. ### Method `dump/3` (function) ### Endpoint `Money.Ecto.Map.Type.dump/3` ``` -------------------------------- ### Configure Money.Ecto.Query.API for MySQL Map Adapter Source: https://context7_llms This snippet shows how to configure the Money.Ecto.Query.API behaviour to use a Map adapter specifically for MySQL. It highlights the potential use of the `Money.Ecto.Query.API.Map.MySQL` adapter, with a caution that it may not be actively maintained. ```elixir use Money.Ecto.Query.API, adapter: Money.Ecto.Query.API.Map.MySQL ``` -------------------------------- ### Money.DDL.execute_each/2 Source: https://context7_llms Executes multiple SQL commands separated by newlines and returns an Ecto-executable string. ```APIDOC ## Money.DDL.execute_each/2 ### Description Returns a string that will Ecto `execute` each SQL command. ### Method `execute_each` (function) ### Endpoint `Money.DDL.execute_each/2` ### Parameters #### Path Parameters - `sql` (string) - Required - A string of SQL commands separated by three newlines (`\n`). ### Request Example ```elixir iex> Money.DDL.execute_each "SELECT name FROM customers;\n\nSELECT id FROM orders;" ``` ### Response #### Success Response - `String` - The Ecto-executable SQL command string for multiple commands. ### Response Example ```elixir "execute \"\nSELECT name FROM customers;\n\nSELECT id FROM orders;\"" ``` ``` -------------------------------- ### Execute Multiple SQL Commands (Elixir) Source: https://context7_llms The `Money.DDL.execute_each/2` function generates a string for Ecto to execute multiple SQL commands. Commands must be separated by three newlines (two blank lines). ```elixir iex> Money.DDL.execute "SELECT name FROM customers;\n\nSELECT id FROM orders;" "execute \"SELECT name FROM customers;\n\nSELECT id FROM orders;\"" ``` -------------------------------- ### Money.DDL.execute/2 Source: https://context7_llms Executes a single SQL command and returns a string suitable for Ecto. ```APIDOC ## Money.DDL.execute/2 ### Description Returns a string that will Ecto `execute` a single SQL command. ### Method `execute` (function) ### Endpoint `Money.DDL.execute/2` ### Parameters #### Path Parameters - `sql` (string) - Required - A single SQL command. ### Request Example ```elixir iex> Money.DDL.execute "SELECT name FROM customers;" ``` ### Response #### Success Response - `String` - The Ecto-executable SQL command string. ### Response Example ```elixir "execute \"SELECT name FROM customers;\"" ``` ``` -------------------------------- ### Money.Ecto.Map.Type.type/1 Source: https://context7_llms Callback implementation for Ecto.ParameterizedType.type/1. ```APIDOC ## Money.Ecto.Map.Type.type/1 ### Description Callback implementation for `Ecto.ParameterizedType.type/1`. ### Method `type/1` (function) ### Endpoint `Money.Ecto.Map.Type.type/1` ``` -------------------------------- ### Money.Ecto.Query.API Usage Source: https://context7_llms Explains how to use the Money.Ecto.Query.API module within your Elixir project and how to configure custom adapters. ```APIDOC ## Usage - Money.Ecto.Query.API (behaviour) In a module where you wish to use these helpers, add: use Money.Ecto.Query.API The default usage is designed to work with the `Money.Ecto.Composite.Type` implementation for Postgres databases. Alternative implementations can be made that comply with the `Money.Ecto.Query.API` behaviour. To use a custom adapter: use Money.Ecto.Query.API, adapter: MyAdapterModule See the Adapters section for more details. ``` -------------------------------- ### Configure Money.Ecto.Query.API for Postgres Map Adapter Source: https://context7_llms This snippet illustrates how to configure the Money.Ecto.Query.API behaviour to use a Map adapter with a Postgres database. This configuration allows leveraging the API's helpers even when using a Map type instead of the default Composite Type for storing money data in Postgres. ```elixir use Money.Ecto.Query.API, adapter: Money.Ecto.Query.API.Map.Postgres ``` -------------------------------- ### Money.Ecto.Map.Type.cast/2 Source: https://context7_llms Callback implementation for Ecto.ParameterizedType.cast/2. ```APIDOC ## Money.Ecto.Map.Type.cast/2 ### Description Callback implementation for `Ecto.ParameterizedType.cast/2`. ### Method `cast/2` (function) ### Endpoint `Money.Ecto.Map.Type.cast/2` ``` -------------------------------- ### Money.Ecto.Query.API Source: https://context7_llms Provides helpers for querying the database for the Money type. ```APIDOC ## Money.Ecto.Query.API ### Description Provides several helpers to query DB for the `Money` type. ### Type Behaviour ``` -------------------------------- ### Use Money.Ecto.Query.API Default Source: https://context7_llms This snippet shows the basic usage of the Money.Ecto.Query.API behaviour in a module. It assumes the default Ecto Composite Type for Postgres databases. No external dependencies are explicitly mentioned for this basic usage. ```elixir use Money.Ecto.Query.API ``` -------------------------------- ### Execute Single SQL Command (Elixir) Source: https://context7_llms The `Money.DDL.execute/2` function generates a string suitable for Ecto to execute a single SQL command. It takes the SQL command as a string argument. ```elixir iex> Money.DDL.execute "SELECT name FROM customers;" "execute \"SELECT name FROM customers;\"" ``` -------------------------------- ### Money.Ecto.Composite.Type.equal?/2 Source: https://context7_llms Compares two money structs for equality. ```APIDOC ## Money.Ecto.Composite.Type.equal?/2 ### Description Compares two money structs and returns a boolean indicating if they are equal. ### Method `equal?/2` (function) ### Endpoint `Money.Ecto.Composite.Type.equal?/2` ### Parameters #### Path Parameters - `money1` (t:Money.t/0) - The first money struct. - `money2` (t:Money.t/0) - The second money struct. ### Returns - `true` or `false`. ``` -------------------------------- ### Money.Ecto.Composite.Type.cast/2 Source: https://context7_llms Casts user input into a `t:Money.t/0` struct, considering locale. ```APIDOC ## Money.Ecto.Composite.Type.cast/2 ### Description Casts user input into a `t:Money.t/0` struct. User input is expected to be in the format for the current locale (as determined by `Cldr.get_locale/0`) or the locale specified by the `:locale` parameter. Be aware of potential misinterpretations if locale and user data are not aligned (e.g., decimal separators). ### Method `cast/2` (function) ### Endpoint `Money.Ecto.Composite.Type.cast/2` ### Parameters #### Path Parameters - `money` (map or string) - A map containing `currency` and `amount` (as strings or atoms), or a string parsable into a `t:Money.t/0` struct. - `params` (keyword list) - Options passed to `Money.new/3`. ### Returns - `{:ok, money}` or `:error` ### Notes - If `money` or `amount` values are `nil`, `{:ok, nil}` is returned. - `amount` can be a string, integer, or `t:Decimal.t/0`. - String parsing uses `Money.parse/2` and is locale-specific. ``` -------------------------------- ### Money.Ecto.Composite.Type.cast/1 Source: https://context7_llms Casts user input into a `t:Money.t/0` struct. ```APIDOC ## Money.Ecto.Composite.Type.cast/1 ### Description Casts user input into a `t:Money.t/0` struct. See `Money.Ecto.Composite.Type.cast/2`. ### Method `cast/1` (function) ### Endpoint `Money.Ecto.Composite.Type.cast/1` ### Parameters #### Path Parameters - `money` - The input to cast. ### Response #### Success Response - `{:ok, money}` or `:error` ``` -------------------------------- ### Money.Ecto.Map.Type.cast/1 Source: https://context7_llms Casts user input into a `t:Money.t/0` struct, referring to `Money.Ecto.Composite.Type.cast/1`. ```APIDOC ## Money.Ecto.Map.Type.cast/1 ### Description Casts user input into a `t:Money.t/0` struct. See `Money.Ecto.Composite.Type.cast/1`. ### Method `cast/1` (function) ### Endpoint `Money.Ecto.Map.Type.cast/1` ### Parameters #### Path Parameters - `money` - The input to cast. ### Response #### Success Response - `{:ok, money}` or `:error` ``` -------------------------------- ### Money.Ecto.Map.Type.embed_as/1 Source: https://context7_llms Returns the embedding strategy, referring to `Money.Ecto.Composite.Type.embed_as/1`. ```APIDOC ## Money.Ecto.Map.Type.embed_as/1 ### Description Returns the embedding strategy. See `Money.Ecto.Composite.Type.embed_as/1`. ### Method `embed_as/1` (function) ### Endpoint `Money.Ecto.Map.Type.embed_as/1` ``` -------------------------------- ### Money.Ecto.Query.API.total_by/3 Source: https://context7_llms Aggregates records by currency, summing the amounts. ```APIDOC ## Money.Ecto.Query.API.total_by/3 (macro) `Ecto.Query.API` helper, allowing to aggregate by currency, summing amount. For more sophisticated aggregation, resort to raw `fragment`. ### Request Example ```elixir Organization |> where([o], o.name == ^"Lemon Inc.") |> total_by([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:EUR, "100"), Money.new(:USD, "210")] ``` ``` -------------------------------- ### Money.Ecto.Composite.Type Source: https://context7_llms Implements Ecto.Type behavior for a user-defined Postgres composite type `:money_with_currency`. ```APIDOC ## Money.Ecto.Composite.Type ### Description Implements the Ecto.Type behaviour for a user-defined Postgres composite type called `:money_with_currency`. This is preferred for Postgres databases as the serialized money amount is stored as a decimal number. ### Methods - `cast/1` - `cast/2` - `equal?/2` - `equal?/3` ``` -------------------------------- ### Money.Ecto.Map.Type.equal?/2 Source: https://context7_llms Compares two money structs for equality, referring to `Money.Ecto.Composite.Type.equal?/2`. ```APIDOC ## Money.Ecto.Map.Type.equal?/2 ### Description Compares two money structs and returns a boolean indicating if they are equal. See `Money.Ecto.Composite.Type.equal?/2`. ### Method `equal?/2` (function) ### Endpoint `Money.Ecto.Map.Type.equal?/2` ### Parameters #### Path Parameters - `money1` (t:Money.t/0) - The first money struct. - `money2` (t:Money.t/0) - The second money struct. ### Returns - `true` or `false`. ``` -------------------------------- ### Money.Ecto.Composite.Type.equal?/3 Source: https://context7_llms Compares two money structs for equality, ignoring extra parameters. ```APIDOC ## Money.Ecto.Composite.Type.equal?/3 ### Description Compares two money structs and returns a boolean indicating if they are equal. The `params` argument is ignored. ### Method `equal?/3` (function) ### Endpoint `Money.Ecto.Composite.Type.equal?/3` ### Parameters #### Path Parameters - `money1` (t:Money.t/0) - The first money struct. - `money2` (t:Money.t/0) - The second money struct. - `params` - Ignored. ### Returns - `true` or `false`. ``` -------------------------------- ### Money.Ecto.Map.Type Source: https://context7_llms Implements Ecto.Type behavior for Money, using a map as the underlying schema type. ```APIDOC ## Money.Ecto.Map.Type ### Description Implements Ecto.Type behaviour for Money, where the underlying schema type is a map. This is required for databases like MySQL that do not support composite types. The amount is serialized as a string to preserve precision, as JSON numeric representation can lead to loss of precision. ### Methods - `cast/1` - `cast/2` - `dump/3` - `embed_as/1` - `equal?/2` - `init/1` - `load/3` - `type/1` ``` -------------------------------- ### Money.Ecto.Query.API.cast_decimal/1 Source: https://context7_llms Callback function to cast a decimal value to a format accepted by the database. ```APIDOC ## Money.Ecto.Query.API.cast_decimal/1 (callback) Cast decimal to the value accepted by the database. ``` -------------------------------- ### Money.Validate Module Source: https://context7_llms Provides Ecto validations for the Money type, compatible with Money.Ecto.Composite.Type. ```APIDOC ## Money.Validate (module) Implements Ecto validations for the `t:Money.t/0` type based upon the `Money.Ecto.Composite.Type` type. ``` -------------------------------- ### Money.Ecto.Query.API.total_by/4 Source: https://context7_llms Aggregates records by a specific currency, summing the amounts. ```APIDOC ## Money.Ecto.Query.API.total_by/4 (macro) `Ecto.Query.API` helper, allowing to aggregate by currency, suming amount. Same as `total_by/3`, but for the single currency only. ### Request Example ```elixir Organization |> where([o], o.name == ^"Lemon Inc.") |> total_by([o], o.payroll, :USD) |> Repo.one() ``` ### Response Example ```elixir [Money.new(:USD, "210")] ``` ``` -------------------------------- ### Money.Ecto.Query.API.currency_eq/2 Source: https://context7_llms Filters records where the currency matches the specified currency code. ```APIDOC ## Money.Ecto.Query.API.currency_eq/2 (macro) `Ecto.Query.API` helper, allowing to filter records having the same currency. ### Request Example ```elixir Organization |> where([o], currency_eq(o.payroll, :AUD)) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:AUD, "50"), Money.new(:AUD, "70")] ``` ``` -------------------------------- ### Money.Ecto.Query.API.money_eq/2 Source: https://context7_llms Filters records where both the monetary amount and currency match the specified Money value. ```APIDOC ## Money.Ecto.Query.API.money_eq/2 (macro) `Ecto.Query.API` helper, allowing to filter records having the same amount and currency. ### Request Example ```elixir Organization |> where([o], money_eq(o.payroll, Money.new!(100, :USD))) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:USD, "100"), Money.new(:USD, "100")] ``` ``` -------------------------------- ### Money.Ecto.Query.API.amount_le/2 Source: https://context7_llms Filters records where the monetary amount is less than or equal to the specified value. ```APIDOC ## Money.Ecto.Query.API.amount_le/2 (macro) `Ecto.Query.API` helper, allowing to filter records having the amount less than or equal to the one given as an argument. ### Request Example ```elixir Organization |> where([o], amount_le(o.payroll, 110)) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:EUR, "100"), Money.new(:USD, "110")] ``` ``` -------------------------------- ### Validate Monetary Value with Comparison Operators Source: https://context7_llms This function validates monetary values using various comparison operators. It takes a changeset, a field name, and options to define the validation rules. Options include :less_than, :greater_than, :less_than_or_equal_to, :greater_than_or_equal_to, :equal_to, and :not_equal_to. A :message option allows for custom error messages on failure. ```elixir validate_money(changeset, :value, less_than: Money.new(:USD, 200)) validate_money(changeset, :value, less_than_or_equal_to: Money.new(:USD, 200)) validate_money(changeset, :value, less_than_or_equal_to: Money.new(:USD, 100)) validate_money(changeset, :value, greater_than: Money.new(:USD, 50)) validate_money(changeset, :value, greater_than_or_equal_to: Money.new(:USD, 50)) validate_money(changeset, :value, greater_than_or_equal_to: Money.new(:USD, 100)) ``` -------------------------------- ### Money.Ecto.Query.API.amount_eq/2 Source: https://context7_llms Filters records where the monetary amount is equal to the specified value. ```APIDOC ## Money.Ecto.Query.API.amount_eq/2 (macro) `Ecto.Query.API` helper, allowing to filter records having the same amount. ### Request Example ```elixir Organization |> where([o], amount_eq(o.payroll, 100)) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:EUR, "100"), Money.new(:USD, "100")] ``` ``` -------------------------------- ### Filter by Exact Money (Amount and Currency) in Ecto Query Source: https://context7_llms This Elixir code snippet utilizes the `money_eq/2` helper from Money.Ecto.Query.API to filter Ecto query results based on both the exact amount and currency. It requires a `Money.new!` struct as the comparison value. ```elixir Organization |> where([o], money_eq(o.payroll, Money.new!(100, :USD))) |> select([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Money.Ecto.Query.API.amount_in/2 Source: https://context7_llms Filters records where the monetary amount falls within a specified range. ```APIDOC ## Money.Ecto.Query.API.amount_in/2 (macro) `Ecto.Query.API` helper, allowing to filter records having the amount in the range given as an argument. Accepts `[min, max]`, `{min. max}`, and `min..max` as a range. ### Request Example ```elixir Organization |> where([o], amount_in(o.payroll, 90..110)) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:EUR, "100"), Money.new(:USD, "100")] ``` ``` -------------------------------- ### Filter by Exact Currency in Ecto Query Source: https://context7_llms This Elixir code snippet demonstrates the use of the `currency_eq/2` helper from Money.Ecto.Query.API to filter Ecto query results based on a specific currency. It takes an Ecto schema alias and the currency code as arguments. ```elixir Organization |> where([o], currency_eq(o.payroll, :AUD)) |> select([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Money.Ecto.Query.API.currency_in/2 Source: https://context7_llms Filters records where the currency is one of the specified currency codes. ```APIDOC ## Money.Ecto.Query.API.currency_in/2 (macro) `Ecto.Query.API` helper, allowing to filter records having one of currencies given as an argument. ### Request Example ```elixir Organization |> where([o], currency_in(o.payroll, [:USD, :EUR])) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:EUR, "100"), Money.new(:USD, "100")] ``` ``` -------------------------------- ### Aggregate Total Amount by Currency in Ecto Query Source: https://context7_llms This Elixir code snippet demonstrates the `total_by/3` helper from Money.Ecto.Query.API for aggregating monetary values by currency. It sums the amounts for each distinct currency present in the query results. For more complex aggregations, raw fragments might be necessary. ```elixir Organization |> where([o], o.name == ^"Lemon Inc.") |> total_by([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Money.Ecto.Query.API.amount_ge/2 Source: https://context7_llms Filters records where the monetary amount is greater than or equal to the specified value. ```APIDOC ## Money.Ecto.Query.API.amount_ge/2 (macro) `Ecto.Query.API` helper, allowing to filter records having the amount greater than or equal to the one given as an argument. ### Request Example ```elixir Organization |> where([o], amount_ge(o.payroll, 90)) |> select([o], o.payroll) |> Repo.all() ``` ### Response Example ```elixir [Money.new(:AUD, "90"), Money.new(:USD, "100")] ``` ``` -------------------------------- ### Filter by Amount Less Than or Equal To in Ecto Query Source: https://context7_llms This Elixir code snippet uses the `amount_le/2` helper from Money.Ecto.Query.API to filter Ecto query results for monetary amounts less than or equal to a given value. It returns records that satisfy this condition. ```elixir Organization |> where([o], amount_le(o.payroll, 110)) |> select([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Filter by Exact Amount in Ecto Query Source: https://context7_llms This Elixir code snippet uses the `amount_eq/2` helper from Money.Ecto.Query.API to filter Ecto query results based on an exact monetary amount. It takes an Ecto schema alias and the target amount as input and returns records where the specified field matches the amount. ```elixir Organization |> where([o], amount_eq(o.payroll, 100)) |> select([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Filter by Amount Greater Than or Equal To in Ecto Query Source: https://context7_llms This Elixir code snippet utilizes the `amount_ge/2` helper from Money.Ecto.Query.API to filter Ecto query results for monetary amounts greater than or equal to a specified value. It operates on an Ecto schema and returns records matching the condition. ```elixir Organization |> where([o], amount_ge(o.payroll, 90)) |> select([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Aggregate Total Amount for a Specific Currency in Ecto Query Source: https://context7_llms This Elixir code snippet uses the `total_by/4` helper from Money.Ecto.Query.API to aggregate the total amount for a single, specified currency. It's a variant of `total_by/3` focused on a particular currency, returning a single result. ```elixir Organization |> where([o], o.name == ^"Lemon Inc.") |> total_by([o], o.payroll, :USD) |> Repo.one() ``` -------------------------------- ### Filter by Currency Within a List in Ecto Query Source: https://context7_llms This Elixir code snippet uses the `currency_in/2` helper from Money.Ecto.Query.API to filter Ecto query results where the currency matches any of the currencies provided in a list. It's useful for selecting records across multiple specific currencies. ```elixir Organization |> where([o], currency_in(o.payroll, [:USD, :EUR])) |> select([o], o.payroll) |> Repo.all() ``` -------------------------------- ### Filter by Amount Within Range in Ecto Query Source: https://context7_llms This Elixir code snippet employs the `amount_in/2` helper from Money.Ecto.Query.API to filter Ecto query results for monetary amounts falling within a specified range. The range can be provided as a list `[min, max]`, a tuple `{min, max}`, or a range operator `min..max`. ```elixir Organization |> where([o], amount_in(o.payroll, 90..110)) |> select([o], o.payroll) |> Repo.all() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.