-
Notifications
You must be signed in to change notification settings - Fork 48
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
Showing
6 changed files
with
296 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
use sqlx::{prelude::FromRow, MySqlPool}; | ||
|
||
#[derive(Deserialize, Serialize, FromRow)] | ||
struct TheiaSession { | ||
cluster_address: Option<String>, | ||
} | ||
|
||
pub async fn get_cluster_address(pool: &MySqlPool, session_id: &str) -> Result<String> { | ||
let row: Option<TheiaSession> = sqlx::query_as( | ||
r#" | ||
SELECT cluster_address | ||
FROM theia_session | ||
WHERE id = ? AND active = 1 | ||
"#, | ||
) | ||
.bind(session_id) | ||
.fetch_optional(pool) | ||
.await?; | ||
|
||
match row { | ||
Some(session) => { | ||
if let Some(cluster_address) = session.cluster_address { | ||
Ok(cluster_address) | ||
} else { | ||
Err(anyhow::anyhow!("cluster address not found")) | ||
} | ||
} | ||
None => Err(anyhow::anyhow!("session not found")), | ||
} | ||
} | ||
|
||
pub async fn update_last_proxy_time(session_id: &str, pool: &MySqlPool) -> Result<()> { | ||
sqlx::query( | ||
r#" | ||
UPDATE theia_session | ||
SET last_proxy = NOW() | ||
WHERE id = ? | ||
"#, | ||
) | ||
.bind(session_id) | ||
.execute(pool) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.