CRUD operations for Ecto schemas exposed via Ectomancer.
This module provides the actual database operations for the auto-generated CRUD tools. It handles:
- Listing records with filters and pagination
- Getting single records by primary key
- Creating records via Ecto changesets
- Updating records via Ecto changesets
- Deleting records
Configuration
The Repo module is automatically detected from your application config:
config :ectomancer, :repo, MyApp.RepoIf not configured, it defaults to trying MyApp.Repo based on your app's
module namespace.
Summary
Functions
Creates a new record.
Deletes a record.
Detects the Repo module based on the application name.
Gets a single record by primary key.
Lists records with optional filters.
Gets the configured Repo module.
Restores a soft-deleted record by setting its soft-delete field to nil.
Updates an existing record.
Validates dynamic include requests against allowed preloadable associations.
Functions
Creates a new record.
Parameters
schema_module- The Ecto schema moduleparams- Map of attributes
Examples
create(MyApp.Accounts.User, %{"email" => "test@example.com", "name" => "Test"})
Deletes a record.
Parameters
schema_module- The Ecto schema moduleparams- Map containing the primary key value
Examples
destroy(MyApp.Accounts.User, %{"id" => 123})
@spec detect_repo() :: module() | nil
Detects the Repo module based on the application name.
Gets a single record by primary key.
Parameters
schema_module- The Ecto schema moduleparams- Map containing the primary key valueopts- Options including:preloadfor eager-loading associations
Examples
get(MyApp.Accounts.User, %{"id" => 123})
get(MyApp.Accounts.User, %{"id" => 123}, preload: [:posts, :comments])
Lists records with optional filters.
Parameters
schema_module- The Ecto schema moduleparams- Map of filter parameters (optional)opts- Options including pagination
Examples
list(MyApp.Accounts.User, %{"email" => "test@example.com"}, limit: 10)
@spec repo() :: module() | nil
Gets the configured Repo module.
Returns the repo from config or attempts to detect it from the application name.
Restores a soft-deleted record by setting its soft-delete field to nil.
Parameters
schema_module- The Ecto schema moduleparams- Map containing the primary key value
Examples
restore(MyApp.Accounts.User, %{"id" => 123})
Updates an existing record.
Parameters
schema_module- The Ecto schema moduleparams- Map containing primary key and updated attributes
Examples
update(MyApp.Accounts.User, %{"id" => 123, "name" => "New Name"})
Validates dynamic include requests against allowed preloadable associations.
Returns the opts keyword list with merged preloads.