Skip to content

feat(orm)!: transactions support#468

Open
m4tx wants to merge 2 commits into
masterfrom
transactions
Open

feat(orm)!: transactions support#468
m4tx wants to merge 2 commits into
masterfrom
transactions

Conversation

@m4tx

@m4tx m4tx commented Feb 1, 2026

Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions Bot added C-lib Crate: cot (main library crate) C-macros Crate: cot-macros labels Feb 1, 2026
@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.63484% with 56 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot/src/db.rs 83.92% 16 Missing and 29 partials ⚠️
cot/src/auth/db.rs 75.00% 3 Missing and 1 partial ⚠️
cot/src/session/store/db.rs 88.57% 0 Missing and 4 partials ⚠️
cot/src/db/sea_query_db.rs 96.05% 0 Missing and 3 partials ⚠️
Flag Coverage Δ
rust 90.08% <86.63%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot-macros/src/model.rs 96.36% <ø> (ø)
cot/src/db/impl_mysql.rs 100.00% <ø> (ø)
cot/src/db/impl_postgres.rs 100.00% <ø> (ø)
cot/src/db/impl_sqlite.rs 94.73% <ø> (ø)
cot/src/db/query.rs 84.16% <100.00%> (+0.58%) ⬆️
cot/src/db/relations.rs 91.66% <100.00%> (ø)
cot/src/db/sea_query_db.rs 96.75% <96.05%> (-0.52%) ⬇️
cot/src/auth/db.rs 82.71% <75.00%> (+0.14%) ⬆️
cot/src/session/store/db.rs 83.13% <88.57%> (+2.05%) ⬆️
cot/src/db.rs 82.95% <83.92%> (-3.88%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown

🐰 Bencher Report

Projectcot
Branchtransactions
Testbedgithub-ubuntu-latest

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
empty_router/empty_routerLatency
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
BenchmarkLatencyBenchmark 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%)
🐰 View full continuous benchmarking report in Bencher

Comment thread examples/admin/src/main.rs Fixed
Copilot AI review requested due to automatic review settings July 22, 2026 20:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Transaction type and internal executor abstraction so ORM operations can run on both &Database and 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.

Comment thread cot/src/db.rs Outdated
Comment thread cot/src/session/store/db.rs Outdated
Copilot AI review requested due to automatic review settings July 23, 2026 17:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Comment thread cot/src/session/store/db.rs
Comment thread cot/src/db.rs Outdated
Comment thread cot/src/session/store/db.rs Outdated
Copilot AI review requested due to automatic review settings July 23, 2026 17:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 uses unwrap()/expect() when building the Session model (JSON serialization + expiry conversion). Those fallible conversions should return a session_store::Error instead of panicking, to avoid crashing the server on unexpected input.
                expiry,
            };

            let res = db.insert(&mut model).await;

Copilot AI review requested due to automatic review settings July 23, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread cot/src/session/store/db.rs
Copilot AI review requested due to automatic review settings July 23, 2026 17:50
@m4tx
m4tx marked this pull request as ready for review July 23, 2026 17:55
@m4tx
m4tx requested a review from ElijahAhianyo July 23, 2026 17:56
@m4tx
m4tx requested a review from seqre July 23, 2026 17:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-lib Crate: cot (main library crate) C-macros Crate: cot-macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants