-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres.rs
More file actions
71 lines (56 loc) · 1.7 KB
/
Copy pathpostgres.rs
File metadata and controls
71 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pub(crate) use sqlx::{
FromRow,
postgres::PgPool,
};
use std::sync::LazyLock;
use crate::prelude::*;
#[inline(always)]
pub fn sql(query: &String) -> sqlx::AssertSqlSafe<&str> {
sqlx::AssertSqlSafe(query.as_str())
}
pub async fn run_migrations(pool: &PgPool) -> Result<()> {
sqlx::migrate!("postgres/migrations")
.dangerous_set_table_name("_platform_migrations")
.run(pool)
.await
.context("Platform postgres migrations failed.")?;
Ok(())
}
pub(crate) static QUERIES: LazyLock<Queries> = LazyLock::new(|| {
get_queries().expect("Failed to initialize platform postgres queries.")
});
#[derive(Deserialize, Debug)]
pub(crate) struct Queries {
pub user: self::internal::User,
pub user_authenticator: self::internal::UserAuthenticator,
}
fn get_queries() -> Result<Queries, config::ConfigError> {
let crate_assets_path = get_crate_assets_path();
let queries_directory = crate_assets_path.join("postgres");
let filename = "queries.yaml";
let settings = config::Config::builder()
.add_source(config::File::from(
queries_directory.join(filename),
))
.build()?;
settings.try_deserialize::<Queries>()
}
mod internal {
use crate::prelude::*;
#[derive(Deserialize, Debug)]
pub struct User {
pub get_by_id: String,
pub get_by_username: String,
pub get_by_email: String,
pub update_email: String,
pub update_data: String,
pub insert: String,
pub delete_by_id: String,
}
#[derive(Deserialize, Debug)]
pub struct UserAuthenticator {
pub get_by_user_id_and_provider: String,
pub verify_local_by_user_id: String,
pub insert: String,
}
}