View Source Introspex.ContextBuilder (Introspex v0.2.0)

Generates Phoenix context modules with CRUD functions for database tables.

Context modules provide a boundary layer between your web interface and data layer, organizing related functionality together. This module generates context files that include standard CRUD operations, with special handling for views that only get read operations.

Summary

Functions

Builds a Phoenix context module with CRUD functions for the given schemas.

Functions

Link to this function

build_context(context_name, schemas, opts)

View Source

Builds a Phoenix context module with CRUD functions for the given schemas.

Parameters

  • context_name - The name of the context (e.g., "Accounts", "Blog")
  • schemas - List of schema information maps containing:
    • :module_name - The schema module name
    • :singular_name - Singular form of the resource name
    • :plural_name - Plural form of the resource name
    • :table_type - Type of database object (:table, :view, or :materialized_view)
  • opts - Keyword list of options:
    • :app_name - The application name
    • :repo_module - The Repo module name
    • :path - Optional path segments to include in module name

Examples

build_context("Accounts", schemas, app_name: "MyApp", repo_module: "MyApp.Repo")

Returns a string containing the complete context module code.