-
Any reason is required to use enums +ident for tables/fields instead of passing a simple string? impl ZoneRow {
fn query() -> SelectStatement {
Query::select().from("zone").to_owned() //not work
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
If you need to, you can do Alias::new("zone"). Or you can There are 2 reasons:
|
Beta Was this translation helpful? Give feedback.
-
Number 1 is still a little unexpected because I was under the impression SeaSQL was for runtime made query building, but I can derive my own Iden easily: struct RawName {
named:String
}
impl Iden for RawName {
fn unquoted(&self, s: &mut dyn Write) {
write!(
s,
"{}",
&self.named
)
.unwrap();
}
} Number 2 makes sense, but this still requiere to return owned query: impl ZoneRow {
fn query() -> &'static mut SelectStatement {
Query::select().from(Tables::Zone) <-- error[E0515]: cannot return value referencing temporary value
}
} Is not a big deal for me, returning SelectStatement is similar to how my own ORM is working now. I close this because exist acceptable workarounds. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your understanding. |
Beta Was this translation helpful? Give feedback.
If you need to, you can do Alias::new("zone").
Or you can
#[derive(Iden)]
struct Zone;
There are 2 reasons:
Correctness. it's an identifier, so if you misspelt it, it'd be a compile error
Efficiency. &str is bad, because the syntax tree needs to store the name until you finally serialize it. Internally it must make a clone of the string (or end up in a lifetime struggle I guess).
But now, the identifier is a pointer, so there is only one unique copy of your string in memory. &'static str would also be great, but then it limits us from runtime behaviour.