Skip to content

Conversation

@pikaju
Copy link
Contributor

@pikaju pikaju commented Nov 12, 2025

Adds custom column names with one of the following syntax options:

#[column("name")]
#[column(type = "type")]
#[column("name", type = "type")]
#[column(type = "type", "name")]

Removes the #[db(type)] attribute.

You can also either specify a varchar type like before:

#[column(type = varchar(5))]

or a custom type with a raw string:

#[column(type = "jsonb")]

Also adds two tests to check if the column was really renamed.

Closes #153

@pikaju pikaju marked this pull request as draft November 12, 2025 19:44
VarChar(u64),

/// User-specified unrecognized type
Custom(&'static str),
Copy link
Member

Choose a reason for hiding this comment

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

We probably want this to be String to allow runtime specification of custom types. I don't think allocations will be an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I changed it to String

@pikaju pikaju marked this pull request as ready for review November 13, 2025 16:51
@pikaju pikaju requested a review from carllerche November 13, 2025 16:55
@pikaju pikaju changed the title WIP: Add support for specifying a different database name for fields Add support for specifying a different database name for fields Nov 13, 2025
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Left a comment inline.

Comment on lines +388 to +389
name: name.app_name.clone(),
storage_name,
Copy link
Member

Choose a reason for hiding this comment

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

I'm OK merging the PR with this, but as a follow up, I don't think we need to track app_name here. app_name is the app-level field name. db::Column is the storage name. If there is something I am missing, let me know.

@carllerche carllerche merged commit 6d3e410 into tokio-rs:main Nov 13, 2025
12 of 13 checks passed
@pikaju pikaju deleted the column-names branch November 13, 2025 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add Field Attribute for Mapping to Different Database Column Names

2 participants