JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Base protocol refactor complete

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨079d544

⁨giterated-daemon/src/backend/settings.rs⁩ - ⁨2606⁩ bytes
Raw
1 use anyhow::Error;
2
3 use giterated_models::model::{repository::Repository, settings::AnySetting, user::User};
4
5 use sqlx::PgPool;
6
7 use super::MetadataBackend;
8
9 pub struct DatabaseSettings {
10 pub pg_pool: PgPool,
11 }
12
13 #[async_trait::async_trait]
14 impl MetadataBackend for DatabaseSettings {
15 async fn user_get(&mut self, _user: &User, _name: &str) -> Result<AnySetting, Error> {
16 todo!()
17 }
18 async fn user_write(
19 &mut self,
20 _user: &User,
21 _name: &str,
22 _value: AnySetting,
23 ) -> Result<(), Error> {
24 // for (name, value) in settings {
25 // sqlx::query!("INSERT INTO user_settings VALUES ($1, $2, $3) ON CONFLICT (username, name) DO UPDATE SET value = $3",
26 // user.username, name, value)
27 // .execute(&self.pg_pool).await?;
28 // }
29
30 // Ok(())
31
32 todo!()
33 }
34
35 async fn repository_get(
36 &mut self,
37 _repository: &Repository,
38 _name: &str,
39 ) -> Result<AnySetting, Error> {
40 // let settings = sqlx::query_as!(
41 // RepositorySettingRow,
42 // r#"SELECT * FROM repository_settings WHERE repository = $1"#,
43 // repository.to_string()
44 // )
45 // .fetch_many(&self.pg_pool)
46 // .filter_map(|result| async move {
47 // if let Ok(Either::Right(row)) = result {
48 // Some(row)
49 // } else {
50 // None
51 // }
52 // })
53 // .filter_map(|row| async move {
54 // if let Ok(value) = serde_json::from_str(&row.value) {
55 // Some((row.name, value))
56 // } else {
57 // None
58 // }
59 // })
60 // .collect::<Vec<_>>()
61 // .await;
62
63 // Ok(settings)
64
65 todo!()
66 }
67 async fn repository_write(
68 &mut self,
69 _repository: &Repository,
70 _name: &str,
71 _value: AnySetting,
72 ) -> Result<(), Error> {
73 // for (name, value) in settings {
74 // sqlx::query!("INSERT INTO repository_settings VALUES ($1, $2, $3) ON CONFLICT (repository, name) DO UPDATE SET value = $3",
75 // repository.to_string(), name, value)
76 // .execute(&self.pg_pool).await?;
77 // }
78
79 // Ok(())
80
81 todo!()
82 }
83 }
84
85 #[allow(unused)]
86 #[derive(Debug, sqlx::FromRow)]
87 struct UserSettingRow {
88 pub username: String,
89 pub name: String,
90 pub value: String,
91 }
92
93 #[allow(unused)]
94 #[derive(Debug, sqlx::FromRow)]
95 struct RepositorySettingRow {
96 pub repository: String,
97 pub name: String,
98 pub value: String,
99 }
100