Lotus.Source (Lotus v1.0.0)

Copy Markdown View Source

Public facade for data sources in Lotus.

Provides convenience functions for resolving, listing, and querying data sources. All functions accept %Adapter{} structs, source name strings, or raw repo modules, resolving lazily as needed.

Summary

Functions

Returns the default source as an %Adapter{} struct.

Return the editor configuration for a source.

Return an example query string suitable for placeholder text.

Gets a source adapter by name. Raises if not found.

Return the human-readable label for the top-level hierarchy in a source.

Wrap a statement with a limit clause using the source's syntax.

Lists all configured source adapters.

Ask the adapter to resolve a statement into a form suitable for optimization analysis (e.g. neutralizing {{var}} placeholders and stripping [[...]] optional clauses so the engine's EXPLAIN / profile endpoint can parse it).

Return the query language identifier for a source.

Resolve to an %Adapter{} struct.

Detect the source type from an adapter, repository module, or name.

Return the Lotus.Query.Filter operators this source's adapter supports.

Whether a source supports a specific feature.

Functions

default_source()

@spec default_source() :: Lotus.Source.Adapter.t()

Returns the default source as an %Adapter{} struct.

editor_config(adapter)

@spec editor_config(Lotus.Source.Adapter.t() | String.t()) :: map()

Return the editor configuration for a source.

example_query(adapter, table, schema)

@spec example_query(
  Lotus.Source.Adapter.t() | String.t(),
  String.t(),
  String.t() | nil
) :: String.t()

Return an example query string suitable for placeholder text.

get_source!(name)

@spec get_source!(String.t()) :: Lotus.Source.Adapter.t()

Gets a source adapter by name. Raises if not found.

hierarchy_label(adapter)

@spec hierarchy_label(Lotus.Source.Adapter.t() | String.t()) :: String.t()

Return the human-readable label for the top-level hierarchy in a source.

limit_query(adapter, statement, limit)

Wrap a statement with a limit clause using the source's syntax.

list_sources()

@spec list_sources() :: [Lotus.Source.Adapter.t()]

Lists all configured source adapters.

prepare_for_analysis(adapter, statement)

@spec prepare_for_analysis(
  Lotus.Source.Adapter.t() | String.t(),
  Lotus.Query.Statement.t()
) ::
  {:ok, Lotus.Query.Statement.t()} | {:error, term()}

Ask the adapter to resolve a statement into a form suitable for optimization analysis (e.g. neutralizing {{var}} placeholders and stripping [[...]] optional clauses so the engine's EXPLAIN / profile endpoint can parse it).

Returns {:error, :unsupported} when the adapter does not implement prepare_for_analysis/2 — callers should treat that as "skip optimization for this source".

query_language(adapter)

@spec query_language(Lotus.Source.Adapter.t() | String.t()) :: String.t()

Return the query language identifier for a source.

resolve!(source_opt, q_source)

@spec resolve!(nil | String.t() | module(), nil | String.t() | module()) ::
  Lotus.Source.Adapter.t()

Resolve to an %Adapter{} struct.

Accepts:

  • source_opt — configured name (string) or source module (atom) or nil
  • q_source — query's stored source (string or module) or nil

Falls back to the default source. Raises on resolution failure.

source_type(repo_or_name)

Detect the source type from an adapter, repository module, or name.

supported_filter_operators(adapter)

@spec supported_filter_operators(Lotus.Source.Adapter.t() | String.t()) :: [atom()]

Return the Lotus.Query.Filter operators this source's adapter supports.

UIs that expose a filter operator dropdown should read this list and gate the options per source — attempting to use an operator outside the declared list raises Lotus.UnsupportedOperatorError when filters are applied.

supports_feature?(adapter, feature)

@spec supports_feature?(Lotus.Source.Adapter.t() | String.t() | module(), atom()) ::
  boolean()

Whether a source supports a specific feature.

Accepts an %Adapter{} struct or a source name/repo module (resolved to adapter).