-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21e6d21
commit 4408782
Showing
3 changed files
with
39 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,42 @@ | ||
// use mysql_async::prelude::*; | ||
|
||
pub struct Database { | ||
// db_pool: mysql_async::Pool, | ||
db_pool: sqlx::mysql::MySqlPool, | ||
} | ||
|
||
impl Database { | ||
pub fn new(_database_url: &str) -> Self { | ||
// let db_pool = mysql_async::Pool::new(database_url); | ||
Database {} | ||
pub fn new(database_url: &str) -> Self { | ||
let db_pool = sqlx::mysql::MySqlPool::connect_lazy(database_url).unwrap(); | ||
Database { db_pool } | ||
} | ||
|
||
// #[allow(dead_code)] | ||
// pub async fn insert_stage_task( | ||
// &self, | ||
// proof_id: &str, | ||
// status: i32, | ||
// context: &str, | ||
// ) -> std::result::Result<bool, String> { | ||
// let mut conn = self.db_pool.get_conn().await.map_err(|e| (e.to_string()))?; | ||
// let stmt = conn | ||
// .prep("INSERT INTO stage_task (id, status, context) values (:id, :status, :context)") | ||
// .await | ||
// .map_err(|e| (e.to_string()))?; | ||
// let params = mysql_async::Params::from(vec![ | ||
// ( | ||
// String::from("id"), | ||
// mysql_async::Value::Bytes(proof_id.as_bytes().to_vec()), | ||
// ), | ||
// ( | ||
// String::from("status"), | ||
// mysql_async::Value::Int(status as i64), | ||
// ), | ||
// ( | ||
// String::from("context"), | ||
// mysql_async::Value::Bytes(context.as_bytes().to_vec()), | ||
// ), | ||
// ]); | ||
// let _: std::result::Result<Vec<String>, String> = | ||
// conn.exec(stmt, params).await.map_err(|e| (e.to_string())); | ||
// Ok(true) | ||
// } | ||
#[allow(dead_code)] | ||
pub async fn insert_stage_task( | ||
&self, | ||
proof_id: &str, | ||
status: i32, | ||
context: &str, | ||
) -> anyhow::Result<bool> { | ||
sqlx::query("INSERT INTO stage_task (id, status, context) values (?,?,?)") | ||
.bind(proof_id) | ||
.bind(status) | ||
.bind(context) | ||
.execute(&self.db_pool) | ||
.await?; | ||
Ok(true) | ||
} | ||
|
||
// #[allow(dead_code)] | ||
// pub async fn update_stage_task( | ||
// &mut self, | ||
// proof_id: &str, | ||
// status: i32, | ||
// result: &str, | ||
// ) -> std::result::Result<bool, String> { | ||
// let mut conn = self.db_pool.get_conn().await.map_err(|e| (e.to_string()))?; | ||
// let stmt = conn | ||
// .prep("UPDATE stage_task set status = :status, result = :result where id = :id)") | ||
// .await | ||
// .map_err(|e| (e.to_string()))?; | ||
// let params = mysql_async::Params::from(vec![ | ||
// ( | ||
// String::from("id"), | ||
// mysql_async::Value::Bytes(proof_id.as_bytes().to_vec()), | ||
// ), | ||
// ( | ||
// String::from("status"), | ||
// mysql_async::Value::Int(status as i64), | ||
// ), | ||
// ( | ||
// String::from("result"), | ||
// mysql_async::Value::Bytes(result.as_bytes().to_vec()), | ||
// ), | ||
// ]); | ||
// let _: std::result::Result<Vec<String>, String> = | ||
// conn.exec(stmt, params).await.map_err(|e| (e.to_string())); | ||
// Ok(true) | ||
// } | ||
#[allow(dead_code)] | ||
pub async fn update_stage_task( | ||
&mut self, | ||
proof_id: &str, | ||
status: i32, | ||
result: &str, | ||
) -> anyhow::Result<bool> { | ||
sqlx::query("UPDATE stage_task set status = ?, result = ? where id = ?)") | ||
.bind(status) | ||
.bind(result) | ||
.bind(proof_id) | ||
.execute(&self.db_pool) | ||
.await?; | ||
Ok(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters