View Source API Reference ecto_forge v0.1.1
Modules
This module allows you to catch Events using callback functions.
Using
Create your callbacks with EctoForge.CreateExtension.Events
defmodule Test.Event.ExtensionDeleteId do
use EctoForge.CreateExtension.Events
def after_get(result) do
result |> Map.delete(:password)
end
def after_created({:ok, item}) do
{:ok, item |> Map.delete(:password)}
end
endConnect to your instansr or DataBaseApi
use EctoForge.CreateInstance,
extensions_events: [MyApp.EctoForge.PasswordDeleter],
repo: MyApp.RepoYou can use callback functions for processing. After the query and before the query to filter the data.
defmodule EctoForge.Extension.Get.Preload do
use EctoForge.CreateExtension.Get
def before_query_add_extension_to_get(_module, _mode, query, attrs) do
preload_attrs = Utls.MapUtls.opts_to_map(attrs)
attrs = Keyword.delete(attrs, :preload)
if is_list(preload_attrs) do
{preload(query, ^preload_attrs), attrs}
else
{query, attrs}
end
end
endCreate your instanse EctoForge and use for your context or Models
Using
defmodule MyApp.EctoForgeInstanse do
use EctoForge.CreateInstance,
extensions_events: [Test.Event.ExtensionDeleteId],
extensions_get: [
EctoForge.Extension.Get.Preload,
EctoForge.Extension.Get.Filter,
EctoForge.Extension.Get.Pagination
],
repo: EctoForge.Repo
endConnect to your model
defmodule EctoForgeTest.UserModel do
use Ecto.Schema
import Ecto.Changeset
@type t() :: %__MODULE__{}
schema "user" do
field(:name, :string)
# timestamps()
end
use EctoForge.CreateInstance
@doc false
def changeset(emails_model \ %__MODULE__{}, attrs) do
emails_model
|> cast(attrs, [:name])
|> validate_required([:name])
end
end
Connect to your context
defmodule MyApp.Context.UserModel do
use MyApp.EctoForgeInstanseBase, module_model: MyApp.UserModel
end
Implements base functions for database
use(
EctoForge.DatabaseApi,
[
repo: MyApp.Repo, # required param
extensions_get: [], # default list
extensions_events: [] # default list
]
)functions find_all, works only with extension EctoForge.Extension.Get.Preload, EctoForge.Extension.Get.Filter or you can write yours own
when not found repo in EctoForge.DatabaseApi
Implements library https://hexdocs.pm/filtery/readme.html
use EctoForge.CreateInstance,
extensions_get: [
EctoForge.Extension.Get.Preload,
],
repo: MyApp.RepoThe helper module is used to perform an extension for the find_all get_all get!() get! functions.
You can use and create your binder