ormx
ormx copied to clipboard
Using attribute `default` with `custom_struct` produces strange compile errors
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
);
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.
Let me reopen this until I get a chance to take a look myself.
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.
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!