feat(orm): add support for raw (r#) model and field names#485
feat(orm): add support for raw (r#) model and field names#485
r#) model and field names#485Conversation
4fc04cc to
3af077b
Compare
|
| Branch | raw-field-names |
| Testbed | github-ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark 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%) |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 constructingPathSegmentidents (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.
| 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(), |
There was a problem hiding this comment.
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.
No description provided.