Builds and runs Ecto queries for Slab.table/1 query mode.
Query support is compiled in only when Ecto is available (it is an optional
dependency). Without Ecto, fetch/4 raises at runtime with instructions.
Everything URL-driven is whitelisted and cast before it touches a query:
sort fields come from <:col sortable> declarations, and cursor values are
cast with Ecto.Type.cast/2 against the schema's field types — invalid
input is ignored, never interpolated.
Summary
Functions
Applies WHERE conditions from the filter URL params.
Applies order_by from the sort and sort_direction params.
Counts the records matching the current filters, ignoring sorting and pagination. Backs the "Showing X to Y of Z entries" summary and the numbered page links in page mode.
Returns the values of an Ecto.Enum field, or nil when the field is
not an enum. Backs automatic select options in the Filters tab.
Runs the queryable through the repo, applying whitelisted sorting and
pagination from params.
Returns the Ecto.Schema module behind a queryable — the module itself,
or the source schema of an %Ecto.Query{}. Returns nil when there is
no schema to reflect on.
Functions
Applies WHERE conditions from the filter URL params.
Only whitelisted columns are ever filtered. Each filter is one of:
- a custom 2-arity function from
<:col filter={...}>— called with(queryable, raw_value)and free to add joins or any Ecto condition - a bare value (
filter[name]=ada) — strings match with a case-insensitive contains, other types cast to an equality check - a list of values (
filter[role][]=a&filter[role][]=b, from multi-select inputs) — becomes afield IN (...)condition - an operator map (
filter[age][gte]=21) — supported operators areeq,neq,gt,gte,lt,lte, andcontains
Declarative values are cast with Ecto.Type.cast/2 against the schema's
field type; anything that fails to cast is ignored, never interpolated.
Applies order_by from the sort and sort_direction params.
Only fields in sortable_fields (a list of atoms, derived from
<:col sortable> declarations) are ever compiled into the query —
anything else in the URL is ignored.
Counts the records matching the current filters, ignoring sorting and pagination. Backs the "Showing X to Y of Z entries" summary and the numbered page links in page mode.
Returns the values of an Ecto.Enum field, or nil when the field is
not an enum. Backs automatic select options in the Filters tab.
Runs the queryable through the repo, applying whitelisted sorting and
pagination from params.
Returns {records, has_next?}. Pagination fetches one extra record to
detect whether a next page exists, avoiding a count query.
Options
:sortable_fields- atoms whitelisted for ORDER BY:filterable_cols- columns whitelisted for WHERE, as maps of%{field: atom, filter: fun | nil}:paginate-nil,:page, or:cursor:per_page- default page size:max_per_page- upper clamp for the URLper_pageparam
Returns the Ecto.Schema module behind a queryable — the module itself,
or the source schema of an %Ecto.Query{}. Returns nil when there is
no schema to reflect on.