Skip to content

feat(orm)!: transactions support - #468

Merged
m4tx merged 1 commit into
masterfrom
transactions
Aug 8, 2026
Merged

feat(orm)!: transactions support#468
m4tx merged 1 commit 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
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
empty_router/empty_router📈 view plot
🚷 view threshold
14,492.00 µs
(+75.96%)Baseline: 8,236.15 µs
15,503.45 µs
(93.48%)
json_api/json_api📈 view plot
🚷 view threshold
1,108.00 µs
(+4.65%)Baseline: 1,058.72 µs
1,383.29 µs
(80.10%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
1,027.90 µs
(+3.93%)Baseline: 989.04 µs
1,263.56 µs
(81.35%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
993.87 µs
(+4.32%)Baseline: 952.68 µs
1,227.11 µs
(80.99%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
16,144.00 µs
(-5.46%)Baseline: 17,077.06 µs
21,559.37 µs
(74.88%)
🐰 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 review from ElijahAhianyo and 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.

@ElijahAhianyo ElijahAhianyo 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.

This looks really cool! Would be nice to have some docs on this in the guide as well :)

Comment thread cot/tests/db.rs Outdated
Comment thread cot/src/db.rs
@m4tx
m4tx force-pushed the transactions branch 2 times, most recently from 25ab4ac to 20da089 Compare August 6, 2026 17:06
@m4tx
m4tx requested review from ElijahAhianyo and a balanced review from Copilot August 6, 2026 17:06

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions github-actions Bot added A-docs Area: Documentation A-deps Area: Dependencies C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) labels Aug 6, 2026
@m4tx
m4tx requested a balanced review from Copilot August 6, 2026 20:37

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 39 out of 40 changed files in this pull request and generated no new comments.

Suppressed comments (3)

cot/src/session/store/db.rs:1

  • The unique-collision retry loop never changes the session key/ID, so a UniqueViolation will deterministically repeat and the retries cannot succeed. On UniqueViolation, regenerate record.id (or otherwise choose a new key), rebuild the model, and retry; if tower-sessions provides a helper for this, use that API to ensure consistent ID format.
//! Database-backed session store.

docs/databases/transactions.md:1

  • The examples use #[model] and LimitedString but only import Auto and Database. To keep the snippets copy-pasteable, either add the missing imports (e.g., use cot::db::{model, LimitedString};) in hidden # lines or switch the example field type from LimitedString<...> to String.
    cot/src/lib.rs:83
  • Changing utils from pub mod utils; to pub(crate) mod utils; is a breaking public API change for downstream crates that may import cot::utils::*. If this is intentional (e.g., because functionality moved to cot-cli), it should be reflected in the crate’s release notes/versioning; otherwise, consider keeping utils public or re-exporting the specific items that are still supported.
pub(crate) mod utils;

Comment thread cot/src/db/migrations.rs
Comment thread docs/databases/transactions.md Outdated
Comment thread cot/tests/db.rs Outdated
Comment thread cot-macros/src/model.rs
Comment thread cot-cli/src/utils.rs Outdated
@m4tx
m4tx force-pushed the transactions branch 3 times, most recently from 629ad59 to 93f50a6 Compare August 7, 2026 18:35
@m4tx
m4tx enabled auto-merge (squash) August 8, 2026 19:06
@m4tx
m4tx merged commit 03b22e9 into master Aug 8, 2026
39 of 40 checks passed
@m4tx
m4tx deleted the transactions branch August 8, 2026 19:28
@cotbot cotbot Bot mentioned this pull request Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-deps Area: Dependencies A-docs Area: Documentation C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) 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.

4 participants