EctoInterface
Creates a common set of interface APIs for ecto models. Some examples include:
list_.../0returns all records for a schemaget_.../1returns a singular record by it's primary keycreate_.../1inserts a new record into the databaserandom_.../returns a random record for a schema
and many more.
All you need to do is use(EctoInterface) on your context modules:
defmodule Core.Users do
use EctoInterface, [Core.Users.Account, :accounts, :account]
endThe first argument is the ecto Schema module, the second is the plural name for the record, and finally the singular.
Additionally if you have slugy installed you can use:
defmodule Core.Users do
use EctoInterface, [Core.Users.Account, :accounts, :account]
use EctoInterface.Read.Slug, [Core.Users.Account, :account]
end
which gives Core.Users.get_account_by_slug("kurtis-rainbolt-greene") (the slug is slugified on query so it doesn't need to be in slug form).
Also, we have a simple interface for tags:
defmodule Core.Users do
use EctoInterface, [Core.Users.Account, :accounts, :account]
use EctoInterface.Read.Tagged, [Core.Users.Account, :accounts]
end
For useful functions like Core.Users.list_accounts_with_tags(["friendly", "sporty]).
Installation
If available in Hex, the package can be installed
by adding ecto_interface to your list of dependencies in mix.exs:
def deps do
[
{:ecto_interface, "~> 1.0.0"}
]
end
And finally in your config/config.exs:
config :ecto_interface, :default_repo, Core.RepoDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ecto_interface.