Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read column with names that conflict with rust reserved keywords? #794

Closed
zaddok opened this issue Aug 22, 2023 · 2 comments
Closed

Comments

@zaddok
Copy link

zaddok commented Aug 22, 2023

Apologies if I missed this somewhere, I can't find it. How do you read column with names that conflict with rust reserved keywords (in the current latest version of the driver).

Consider this example where I can't load the type column because I can't use type as a field name in a rust struct.

struct RequestToken {
    uid: String,
    data: String,
    ip: String,
    request_type: String,
    expiry: i32,
}

if let Some(rows) = session
        .query(
            "SELECT uid, data, ip, type, expiry FROM request_token", &[],)
        .await?
        .rows
@piodul
Copy link
Collaborator

piodul commented Aug 22, 2023

Currently, the driver completely ignores the field names in the FromRow macro and assumes that the order of the columns is the same as the order of the Rust struct fields. You can give any name to the struct field. This will be changed in the future, though, to increase safety (#463, #462).

As a side note, Rust has a concept of raw identifiers - so if you want to have a field named type you can spell it out as r#type: https://doc.rust-lang.org/rust-by-example/compatibility/raw_identifiers.html

@zaddok
Copy link
Author

zaddok commented Aug 22, 2023

Amazing, thank you. It didn't occur to me that the field names might not matter. (Thanks for the tip about rust raw identifiers, I was not aware of that!)

@zaddok zaddok closed this as completed Aug 23, 2023
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

No branches or pull requests

2 participants