this repo has no description
1use sqlx::PgPool; 2use super::super::{AuthorizedClientData, OAuthError}; 3use super::helpers::{from_json, to_json}; 4pub async fn upsert_authorized_client( 5 pool: &PgPool, 6 did: &str, 7 client_id: &str, 8 data: &AuthorizedClientData, 9) -> Result<(), OAuthError> { 10 let data_json = to_json(data)?; 11 sqlx::query!( 12 r#" 13 INSERT INTO oauth_authorized_client (did, client_id, created_at, updated_at, data) 14 VALUES ($1, $2, NOW(), NOW(), $3) 15 ON CONFLICT (did, client_id) DO UPDATE SET updated_at = NOW(), data = $3 16 "#, 17 did, 18 client_id, 19 data_json 20 ) 21 .execute(pool) 22 .await?; 23 Ok(()) 24} 25pub async fn get_authorized_client( 26 pool: &PgPool, 27 did: &str, 28 client_id: &str, 29) -> Result<Option<AuthorizedClientData>, OAuthError> { 30 let row = sqlx::query_scalar!( 31 r#" 32 SELECT data FROM oauth_authorized_client 33 WHERE did = $1 AND client_id = $2 34 "#, 35 did, 36 client_id 37 ) 38 .fetch_optional(pool) 39 .await?; 40 match row { 41 Some(v) => Ok(Some(from_json(v)?)), 42 None => Ok(None), 43 } 44}