Skip to content

feat(orm): add support for raw (r#) model and field names#485

Open
m4tx wants to merge 3 commits intomasterfrom
raw-field-names
Open

feat(orm): add support for raw (r#) model and field names#485
m4tx wants to merge 3 commits intomasterfrom
raw-field-names

Conversation

@m4tx
Copy link
Member

@m4tx m4tx commented Feb 21, 2026

No description provided.

@github-actions github-actions bot added C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) C-macros Crate: cot-macros C-codegen Crate: cot-codegen labels Feb 21, 2026
@github-actions
Copy link

github-actions bot commented Feb 21, 2026

🐰 Bencher Report

Branchraw-field-names
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
5,339.90 µs
(-9.50%)Baseline: 5,900.62 µs
7,029.69 µs
(75.96%)
json_api/json_api📈 view plot
🚷 view threshold
1,012.00 µs
(-0.54%)Baseline: 1,017.45 µs
1,157.83 µs
(87.40%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
955.77 µs
(+1.84%)Baseline: 938.51 µs
1,062.79 µs
(89.93%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
923.65 µs
(+2.73%)Baseline: 899.08 µs
1,020.29 µs
(90.53%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
16,405.00 µs
(-6.28%)Baseline: 17,504.15 µs
20,692.35 µs
(79.28%)
🐰 View full continuous benchmarking report in Bencher

@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot-macros/src/query.rs 69.23% 2 Missing and 2 partials ⚠️
Flag Coverage Δ
rust 89.65% <80.95%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
cot-codegen/src/model.rs 94.20% <100.00%> (+0.10%) ⬆️
cot-codegen/src/symbol_resolver.rs 97.66% <100.00%> (ø)
cot-macros/src/query.rs 70.83% <69.23%> (+1.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@m4tx m4tx marked this pull request as ready for review February 26, 2026 13:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for Rust raw identifiers (r#...) in ORM model/field names so database identifiers (table/column names) are generated without the r# prefix while the Rust Ident is preserved.

Changes:

  • Use quote::format_ident! in the symbol resolver when constructing PathSegment idents (supports raw identifiers).
  • Strip raw-ident prefixes via IdentExt::unraw() when deriving model table names and field column names.
  • Add unit/integration tests covering keyword/raw identifier scenarios in model parsing and migration generation.

Reviewed changes

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

File Description
cot-codegen/src/symbol_resolver.rs Builds path segments with format_ident! to correctly handle raw identifiers in resolved paths.
cot-codegen/src/model.rs Uses unraw() for table/column name derivation and adds unit tests for raw names.
cot-cli/tests/migration_generator/keywords.rs Adds a keyword/raw-identifier model fixture used by migration generator tests.
cot-cli/tests/migration_generator.rs Adds integration tests validating generated migrations and source contain correct identifiers for keyword/raw names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +208 to 212
let name = self.ident.clone().expect("Only structs are supported");
let column_name = name.unraw().to_string();

let (auto_value, foreign_key) = (
self.find_type("cot::db::Auto", symbol_resolver).is_some(),
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

FieldOpts::as_field uses expect("Only structs are supported"), but the panic described above is specifically about tuple (unnamed) fields. Since ident: Option<Ident> is None for tuple struct fields (which are still structs), the message is misleading; consider changing it to something like "Only named struct fields are supported". Also, name is cloned multiple times (clone() on the Option and then again when constructing Field); you can avoid one clone by borrowing the ident or by moving it once into the Field.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) C-codegen Crate: cot-codegen C-macros Crate: cot-macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants