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

Using attribute default with custom_struct produces strange compile errors #20

Open
LouisGariepy opened this issue Dec 9, 2021 · 4 comments · May be fixed by #24
Open

Using attribute default with custom_struct produces strange compile errors #20

LouisGariepy opened this issue Dec 9, 2021 · 4 comments · May be fixed by #24

Comments

@LouisGariepy
Copy link

LouisGariepy commented Dec 9, 2021

Sorry for not having a more minimal example (I might post one soonish) but this should be fairly straightforward if not minimal.

This code gives : wildcard overrides are only allowed with an explicit record type, e.g. query_as!() and its variants

#[derive(Debug, ormx::Table)]
#[ormx(
    table = "Account",
    id = id,
    insertable,
    deletable
)]
pub struct Account {
    #[ormx(default, get_many=get_many_by_id)]
    id: i32,
    #[ormx(get_one, get_many=get_many_by_email, set)]
    email: String,
    #[ormx(set)]
    password_hash: String,
    #[ormx(default)]
    creation_time: OffsetDateTime,
    #[ormx(default, custom_type, set)]  //<-- removing the default attribute fixes the compile error
    account_type: AccountType,
    #[ormx(default, set)]
    suspended: bool,
}

Here's the custom type in question :

#[derive(
    PartialEq, Debug, Copy, Clone, sqlx::Type, Serialize, Deserialize, AsRefStr, IntoStaticStr,
)]
#[sqlx(type_name = "AccountType")]
pub enum AccountType {
    Temporary,
    Guest,
    Admin,
}

And here's the database schema I'm compiling against :

CREATE TABLE Account
(
    id            SERIAL UNIQUE,
    email         TEXT PRIMARY KEY,
    password_hash TEXT                     NOT NULL,
    creation_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    account_type  AccountType              NOT NULL DEFAULT 'Temporary',
    suspended     BOOLEAN                  NOT NULL DEFAULT false
);
@LouisGariepy
Copy link
Author

I will close the issue for now since I no longer have interest in isolating the underlying problems. It also seems I'm the only one hitting this particular problem.

@NyxCode
Copy link
Owner

NyxCode commented Dec 17, 2021

Let me reopen this until I get a chance to take a look myself.

@NyxCode NyxCode reopened this Dec 17, 2021
@benluelo
Copy link

I am getting this issue as well, using a newtype id field. Has there been any progress on this? I would be happy to help out in fixing it.

@benluelo
Copy link

Update on this: it seems that replacing the [...] RETURNING field AS \"field: _\" with [...] RETURNING field AS \"field: ConcreteType\" fixes the issue. I will put together a PR!

@benluelo benluelo linked a pull request Jan 30, 2022 that will close this issue
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 a pull request may close this issue.

3 participants