SelectoMix.SchemaIntrospector (selecto_mix v0.4.7)
Unified interface for introspecting schemas from any source.
Supports both Ecto schemas and direct database connections via Postgrex.
This module provides backward compatibility with the original Ecto-only
interface while delegating to SelectoMix.Introspector (and its backends,
e.g. SelectoMix.Introspector.Ecto) under the hood.
Usage
# Ecto schema (original interface - still works)
config = SelectoMix.SchemaIntrospector.introspect_schema(MyApp.User)
# Postgrex connection (new interface)
{:ok, conn} = Postgrex.start_link(...)
config = SelectoMix.SchemaIntrospector.introspect_schema(
{:postgrex, conn, "users"}
)
Summary
Functions
Extract additional metadata about the schema.
Generate suggested default configuration based on schema analysis.
Extract association information for join configuration.
Map Ecto field types to Selecto types.
Get the primary key field(s) for an Ecto schema.
Get all fields defined in an Ecto schema.
Get the database table name for an Ecto schema.
Introspect a schema source and return Selecto domain configuration data.
Same as introspect_schema/2, but raises Mix.Error on failure and
returns the config map directly. Intended for use at Mix task boundaries.
Introspects a schema while preserving success and failure as tagged tuples.
Functions
Extract additional metadata about the schema.
Generate suggested default configuration based on schema analysis.
Extract association information for join configuration.
Delegates to SelectoMix.Introspector.Ecto.get_associations/2, which
additionally covers :many_to_many associations (with join_through /
join_keys) that this module's earlier standalone implementation did not.
Map Ecto field types to Selecto types.
Delegates to SelectoMix.Introspector.Ecto.get_field_types/1.
Get the primary key field(s) for an Ecto schema.
Delegates to SelectoMix.Introspector.Ecto.get_primary_key/1, which
returns the full list of keys for composite primary keys and nil when
the schema has none (rather than collapsing to a single field or :id).
Get all fields defined in an Ecto schema.
Delegates to SelectoMix.Introspector.Ecto.get_schema_fields/1.
Get the database table name for an Ecto schema.
Delegates to SelectoMix.Introspector.Ecto.get_table_name/1.
Introspect a schema source and return Selecto domain configuration data.
Accepts either an Ecto schema module or a Postgrex connection tuple.
Parameters
source- Either:- Ecto schema module (e.g.,
MyApp.User) {:postgrex, conn, table_name}tuple{:postgrex, conn, table_name, schema}tuple
- Ecto schema module (e.g.,
Options
:include_associations- Include schema associations as joins (default: true):redact_fields- List of field names to mark as redacted:default_limit- Default limit for queries (default: 50):include_timestamps- Include timestamp fields in default selects (default: false)
Returns
A configuration map containing:
:schema_module- The source module or table name:table_name- Database table name:primary_key- Primary key field name:fields- List of all available fields:field_types- Map of field names to their Selecto types:associations- Association metadata for joins:suggested_defaults- Recommended default configuration:redacted_fields- Fields that should be excluded from queries On failure, the map contains:errorand:schema_module, matching the original public API. Useintrospect_schema_result/2when tagged tuples are preferable.
Same as introspect_schema/2, but raises Mix.Error on failure and
returns the config map directly. Intended for use at Mix task boundaries.
Introspects a schema while preserving success and failure as tagged tuples.
Use this at task boundaries that need to stop generation on an introspection
failure. introspect_schema/2 retains the package's original map-returning
API for backward compatibility.