Expand description
Safe SQL builder: identifiers from config only, values as parameters.
Re-exports§
pub use rsql::parse_rsql;pub use rsql::parse_sort;pub use rsql::FilterNode;pub use rsql::RsqlOp;pub use rsql::SortSpec;pub use params::*;
Modules§
- params
- Convert serde_json::Value to bindable SQL parameter values across all dialects.
- rsql
- RSQL filter and sort parser.
Structs§
- Include
Select - Describes one include for single-query list: name, direction, related entity, our key column, their key column.
- Query
Buf
Functions§
- archive
- UPDATE by id: stamp archive_field with NOW() where it is currently NULL. Returns the updated row or None (record not found or already archived).
- coerce_
json_ value_ for_ pg_ array - Postgres array columns: API accepts JSON
["a","b"]; bind as array literal +$n::varchar(255)[]etc. - delete
- DELETE by id.
- insert
- INSERT: columns and placeholders from entity; values from body. Excludes PK if has_default.
Omits columns with DB default when body does not provide a value (so DB uses default).
Uses SQL cast (e.g. $n::timestamptz) for timestamp columns so string values bind correctly.
When
rls_tenant_idis Some, appends tenant_id column and value (for RLS strategy). - insert_
history_ snapshot - INSERT INTO {table}_history: copy the current row from the main table before an update/delete. Uses a single INSERT … SELECT so the snapshot is atomic and never goes through the app layer. Binds: $1 = operation text (“update” | “delete”), $2 = pk value.
- prune_
history - DELETE old history rows beyond keep_versions for a given pk. Binds: $1 = pk value, $2 = keep_versions (bigint).
- rsql_
to_ sql - Convert a
FilterNodetree into a SQL WHERE fragment (no leadingWHERE). All values are pushed as parameters intoq; identifiers come only from config (never from user input) so SQL injection is structurally impossible. - select_
by_ column_ in - SELECT * FROM entity WHERE column IN ($1, $2, …) ORDER BY pk. Used for batch-fetching related rows (to_many or to_one by key).
- select_
by_ id - SELECT by primary key (single column PK only). Caller adds id as sole param.
- select_
history_ by_ version - SELECT a specific version from history for a given pk. Binds: $1 = pk value, $2 = version (bigint).
- select_
history_ list - SELECT all history rows for a given pk, ordered newest first. Binds: $1 = pk value.
- select_
list - SELECT list with optional RSQL filter and sort specs.
filter_includesis needed when the filter contains dotted-field conditions (e.g.transport_unit.bay=contains=bay23) that generate EXISTS subqueries. Pass an empty slice when there are no such filters. - select_
list_ with_ includes - SELECT list with includes in a single query: main table aliased as “main”, each include as a scalar subquery (json_agg for to_many, row_to_json for to_one).
includesdrives the scalar subqueries (response data);filter_includesis the superset used for EXISTS generation when the filter references dotted fields liketransport_unit.bay. - unarchive
- UPDATE by id: clear archive_field (set to NULL) where it is currently NOT NULL. Returns the updated row or None (record not found or not archived).
- update
- UPDATE by id: SET only columns present in body (and in entity columns). Uses SQL cast for timestamp columns so string values bind correctly.