apps: sql + get valid one, get by id, insert, generate app id, generate secret
This commit is contained in:
parent
b5c2be6c9f
commit
71b083895d
19 changed files with 490 additions and 0 deletions
|
|
@ -1,7 +1,9 @@
|
|||
mod apps;
|
||||
mod keys;
|
||||
mod settings;
|
||||
mod users;
|
||||
|
||||
pub use apps::Apps;
|
||||
pub use keys::Keys;
|
||||
pub use settings::Settings;
|
||||
pub use users::Users;
|
||||
|
|
|
|||
62
crates/database/src/tables/apps.rs
Normal file
62
crates/database/src/tables/apps.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
use crate::error::{handle_error, Error};
|
||||
use sqlx::sqlite::SqliteQueryResult;
|
||||
use sqlx::types::chrono::{DateTime, Utc};
|
||||
use sqlx::{FromRow, SqliteExecutor};
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct Apps {
|
||||
pub id: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub label: String,
|
||||
pub redirect_uri: String,
|
||||
pub secret: String,
|
||||
pub is_confidential: bool,
|
||||
pub is_archived: bool,
|
||||
}
|
||||
|
||||
impl Apps {
|
||||
pub async fn insert(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
label: &str,
|
||||
redirect_uri: &str,
|
||||
secret: &str,
|
||||
is_confidential: bool,
|
||||
) -> Result<Option<()>, Error> {
|
||||
let query: SqliteQueryResult = sqlx::query_file!(
|
||||
"queries/apps/insert.sql",
|
||||
id,
|
||||
label,
|
||||
redirect_uri,
|
||||
secret,
|
||||
is_confidential
|
||||
)
|
||||
.execute(conn)
|
||||
.await
|
||||
.map_err(handle_error)?;
|
||||
|
||||
Ok((query.rows_affected() == 1).then_some(()))
|
||||
}
|
||||
|
||||
pub async fn get_one(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
redirect: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
sqlx::query_file_as!(Self, "queries/apps/get_one.sql", id, redirect)
|
||||
.fetch_optional(conn)
|
||||
.await
|
||||
.map_err(handle_error)
|
||||
}
|
||||
|
||||
pub async fn get_one_by_id(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
sqlx::query_file_as!(Self, "queries/apps/get_one_by_id.sql", id)
|
||||
.fetch_optional(conn)
|
||||
.await
|
||||
.map_err(handle_error)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue