pub struct TableAttr {
pub table: Option<LitStr>,
pub insertable: Option<Ident>,
pub insert: Option<LitStr>,
pub extra_derives: Option<Vec<Ident>>,
pub returns: Option<LitStr>,
pub database: Option<LitStr>,
}
Expand description
Available attributes on a struct
Fields§
§table: Option<LitStr>
The name of the table in the database. Defaults to the struct name. Example: #[ormlite(table = “users”)] pub struct User { pub id: i32, }
insertable: Option<Ident>
Deprecated name for insert
Used as #[ormlite(insertable = InsertUser)]
insert: Option<LitStr>
The struct name of an insertion struct. Example: #[ormlite(insert = “InsertUser”)] pub struct User { pub id: i32, }
extra_derives: Option<Vec<Ident>>
Add extra derives to the insertion structs. Example: #[ormlite(insert = “InsertUser”, extra_derives(Serialize, Deserialize))] pub struct User { pub id: i32, }
returns: Option<LitStr>
Only used for derive(Insert) Example: #[ormlite(returns = “User”)] pub struct InsertUser {}
database: Option<LitStr>
Set the target database. Only needed if you have multiple databases enabled.
If you have a single database enabled, you don’t need to set this.
Even with multiple databases, you can skip this by setting a default database with the default-<db>
feature.
Currently, because methods conflict, you
You can use this attribute multiple times to set multiple databases.
Example:
#[ormlite(database = “postgres”)]
#[ormlite(database = “sqlite”)]
pub struct User {
pub id: i32,
}
This will generate orm code for User
for both the postgres
and sqlite
databases.