我看到了来自diesel.rs文档的示例,例如:
#[derive(Insertable)]
#[table_name="users"]
pub struct NewUser<'a> {
pub first_name: &'a str,
pub last_name: &'a str,
pub email: Option<&'a str>,
}
并且
#[derive(Insertable)]
#[table_name="posts"]
pub struct NewPost<'a> {
pub title: &'a str,
pub body: &'a str,
}
事实上,每个官方示例都为Insertable指定了一个生命周期参数。然而,在我阅读github上的真实示例时,我看到的每个Insertable结构都省略了生命周期参数,而是定义了类似的结构体:
#[derive(Insertable)]
#[table_name = "users"]
pub struct CreateUser {
first_name: String,
last_name: String,
role: i16,
}
在数据库性能方面,两种方法是否有优劣之分?如果我采用其中一种方法,是否会遇到问题?
String
实例,您可以仅传递它们的切片而不是克隆它们。 - apetranzilla