Skip to main content

Module statement

Module statement 

Source
Expand description

Statement preparation — building SQL synchronously, so the futures that run it are Send.

§Why this module exists

Rainier ORM’s repo:: functions build a sea_query statement and then await the executor with that statement still in scope. sea_query’s statement types hold Rc<dyn Iden>, so the statement is !Send, so the generated future is !Send — and a future that is not Send cannot be awaited inside a handler that a multi-threaded server will tokio::spawn.

The fix is one line upstream (drop(stmt);, or scoping the build, before the await). Until Rainier ORM does that, Rainier prepares statements here instead: every sea_query value is created and dropped inside a synchronous function, which hands back a Prepared holding only String and Value — both Send. The await then touches nothing that is not Send.

§What is not re-implemented

The metadata, the dialect rendering, the column types, the row decoding and the shard-routing rule all still come from Rainier ORM. This module is a thin re-statement of repo::’s SQL shapes against the same Entity metadata — not a second ORM. In particular, routing behaviour is deliberately identical to Rainier ORM’s, so a sharded deployment routes the same way whether a query goes through here or through repo:: directly.

Structs§

Prepared
A rendered statement: SQL, its ordered bind values, and where to run it.

Functions§

count_grouped
SELECT column, COUNT(*) AS cnt … GROUP BY column.
count_matching
SELECT COUNT(*) AS cnt under a Criteria’s filters and joins only.
delete_by_pk
DELETE FROM table WHERE pk = ?.
delete_matching
DELETE FROM table WHERE <criteria>.
insert
INSERT INTO table (…) VALUES (…).
route_for
The route for constraining column to value on E.
routing_key
Reduce a bound value to a u64 routing key.
select_all
SELECT … FROM table — every row.
select_by_column
SELECT … WHERE column = ?, optionally limited.
select_by_pk
SELECT … WHERE pk = ? LIMIT 1.
select_matching
SELECT … under a Criteria’s filters, joins, ordering and paging.
select_pivot
SELECT parent, related FROM pivot WHERE parent IN (…).
shard_key_for_insert
Whether E needs a connector-minted primary key for this row, and the shard key to mint it from.
update
UPDATE table SET … WHERE pk = ? — every non-key column.
update_matching
UPDATE table SET … WHERE <criteria> — only the named columns.
upsert
INSERT … ON CONFLICT (…) DO UPDATE.