cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Support for transactions with BEGIN ... END and/or multi-insert statements #248

Open jvdwrf opened 1 month ago

jvdwrf commented 1 month ago

Currently, it's possible to create transactions with rollback, however these transactions have to communicate multiple times with the database.

It would be great if transactions like the following would be supported:

--! multi_table_insert(param_a, param_b):
BEGIN;

INSERT INTO a (param_a) VALUES (:param_a);
INSERT INTO b (param_b) VALUES (:param_b);

COMMIT;

Additionally, support for statements with multiple INSERTs:

--! some_function(..)
WITH value AS (
    INSERT INTO ... VALUES ... RETURNING ...
) INSERT INTO ... VALUES ...;