Aurora.Ctx

A powerful DSL for automatically generating CRUD operations in Elixir context modules from Ecto schemas. Aurora.Ctx provides:

Installation

If available in Hex, the package can be installed by adding aurora_ctx to your list of dependencies in mix.exs:

def deps do
[
{:aurora_ctx, "~> 0.1.0"}
]
end

Usage

Add Aurora.Ctx to your context module and register your schemas:

defmodule MyApp.Inventory do
use Aurora.Ctx
# Basic usage with default repo
ctx_register_schema(Product)
# With custom options
ctx_register_schema(Category, MyCustomRepo,
changeset_function: :custom_changeset,
create_changeset_function: :creation_changeset
)
end

Generated Functions

For a schema named Product with source "products", the following functions are automatically generated:

# List operations
list_products() # List all products
list_products(opts) # List with opts
list_products_paginated() # List products with pagination
list_products_paginated(opts) # List with pagination options
count_products() # Count total products
count_products(opts) # Count with filters
# Create operations
create_product(%{name: "Item"}) # Create with attributes
create_product!(%{name: "Item"}) # Create with raising version
create_product() # Create with empty attributes
create_product!() # Create empty with raising version
# Read operations
get_product(1) # Get by ID
get_product!(1) # Get by ID (raises if not found)
get_product(1, preload: [:items]) # Get by ID with preloads
get_product!(1, preload: [:items]) # Get by ID with preloads (raises)
# Update operations
update_product(product, attrs) # Update existing product
update_product(product) # Update without new attributes
change_product(product, attrs) # Create a changeset
change_product(product) # Create changeset without attrs
# Delete operations
delete_product(product) # Delete a product
delete_product!(product) # Delete (raises on error)
# Initialize operations
new_product() # Create new struct
new_product(attrs) # Create with attributes
new_product(attrs, opts) # Create with attributes and options

Documentation

For detailed usage examples and API reference, please see: