feat(orm)!: transactions support#468
Conversation
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
|
| Project | cot |
| Branch | transactions |
| Testbed | github-ubuntu-latest |
🚨 1 Alert
| Benchmark | Measure Units | View | Benchmark Result (Result Δ%) | Upper Boundary (Limit %) |
|---|---|---|---|---|
| empty_router/empty_router | Latency milliseconds (ms) | 📈 plot 🚷 threshold 🚨 alert (🔔) | 13.45 ms(+85.47%)Baseline: 7.25 ms | 12.55 ms (107.19%) |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| empty_router/empty_router | 📈 view plot 🚷 view threshold 🚨 view alert (🔔) | 13.45 ms(+85.47%)Baseline: 7.25 ms | 12.55 ms (107.19%) |
| json_api/json_api | 📈 view plot 🚷 view threshold | 1.12 ms(+3.82%)Baseline: 1.08 ms | 1.37 ms (82.07%) |
| nested_routers/nested_routers | 📈 view plot 🚷 view threshold | 1.06 ms(+5.58%)Baseline: 1.01 ms | 1.24 ms (85.45%) |
| single_root_route/single_root_route | 📈 view plot 🚷 view threshold | 1.01 ms(+4.67%)Baseline: 0.97 ms | 1.21 ms (84.13%) |
| single_root_route_burst/single_root_route_burst | 📈 view plot 🚷 view threshold | 17.02 ms(-2.04%)Baseline: 17.37 ms | 21.69 ms (78.47%) |
There was a problem hiding this comment.
Pull request overview
Adds first-class transaction support to Cot’s ORM layer and updates higher-level components (session store, auth, examples, and macros) to execute ORM operations against either a direct database connection or an in-flight transaction.
Changes:
- Introduces a
Transactiontype and internal executor abstraction so ORM operations can run on both&Databaseand transactions (including nested transactions/savepoints). - Refactors ORM APIs (
DatabaseBackend,Model,Query,ForeignKey, auth DB helpers) to accept mutable executors and support transactional execution. - Updates session store and example app initialization to use transactions; adds new DB tests covering commit/rollback/nested behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/admin/src/main.rs | Uses a DB transaction when ensuring the admin user exists. |
| cot/tests/db.rs | Adds tests for transaction commit, rollback, and nested transactions. |
| cot/src/session/store/db.rs | Wraps session save in a transaction and reuses create logic via an executor parameter. |
| cot/src/session/store/db.rs | (same file) Adjusts DB calls to work with either connection or transaction. |
| cot/src/db/sea_query_db.rs | Exposes backend macro internally and adds a SeaQuery-based transaction backend macro. |
| cot/src/db/relations.rs | Updates foreign key loading to operate on a mutable executor. |
| cot/src/db/query.rs | Refactors query execution to accept a generic mutable DatabaseBackend, including count. |
| cot/src/db/impl_sqlite.rs | Wires in the SeaQuery transaction backend for SQLite. |
| cot/src/db/impl_postgres.rs | Wires in the SeaQuery transaction backend for PostgreSQL. |
| cot/src/db/impl_mysql.rs | Wires in the SeaQuery transaction backend for MySQL. |
| cot/src/db.rs | Adds Transaction, executor plumbing, and updates DatabaseBackend to be &mut self-based. |
| cot/src/auth/db.rs | Updates auth DB helpers/tests to work with the new mutable-executor ORM APIs. |
| cot-macros/src/model.rs | Updates generated Model impls to use cot::db::async_trait and the new executor signatures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
cot/src/session/store/db.rs:136
- This helper is used by
create()/save()but still usesunwrap()/expect()when building theSessionmodel (JSON serialization + expiry conversion). Those fallible conversions should return asession_store::Errorinstead of panicking, to avoid crashing the server on unexpected input.
expiry,
};
let res = db.insert(&mut model).await;
No description provided.