因为这是一个高调用函数,如果我const QUERY
在里面或外面声明有什么区别吗fn insert()
?
impl Player {
pub async fn insert(
db: sqlx::PgConnection,
input: &InputPlayer,
) -> Result<Self> {
const QUERY: &str = r#"INSERT INTO "player" ("team_id", "id", "other_fields") VALUES ($1, $2, $3, $4, $5, $6, $7)"#;
let result = sqlx::query_as::<_, Self>(QUERY)
.bind(input.team_id())
.bind(input.id())
.bind(input.other())
.bind(input.other())
.bind(input.other())
.bind(input.other())
.fetch_one(db)
.await?;
Ok(result)
}
}