Random stuff, testing things, and so on.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
681 B

//! Uma entidade
use sqlx::{Any, Pool};
const INSERT: &str = r#"
INSERT INTO entity
(id, description)
VALUES
($1, $2);
"#;
#[derive(sqlx::FromRow)]
pub struct Entity {
#[sqlx(rename = "chave")]
id: i64,
#[sqlx(rename = "descricao")]
description: String,
}
impl Entity {
pub fn new(id: i64, description: &str) -> Self {
Self {
id,
description: description.into(),
}
}
pub async fn save(&self, db: &Pool<Any>) -> Result<(), sqlx::Error> {
sqlx::query(INSERT)
.bind(&self.id)
.bind(&self.description)
.execute(db)
.await?;
Ok(())
}
}