HOLY FLUFFING GOOBER IT COMPILES
This commit is contained in:
		
							parent
							
								
									66704b4e2e
								
							
						
					
					
						commit
						61ae1b1b53
					
				| 
						 | 
				
			
			@ -12,7 +12,7 @@ pub struct Award {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for Award {
 | 
			
		||||
impl TableMeta for Award {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "awards";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ pub struct Mission {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for Mission {
 | 
			
		||||
impl TableMeta for Mission {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "missions";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ pub struct Qualification {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for Qualification {
 | 
			
		||||
impl TableMeta for Qualification {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "qualifications";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ pub struct Rank {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for Rank {
 | 
			
		||||
impl TableMeta for Rank {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "ranks";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ pub struct Training {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for Training {
 | 
			
		||||
impl TableMeta for Training {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "trainings";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,21 +12,22 @@ pub mod records;
 | 
			
		|||
pub mod sessions;
 | 
			
		||||
pub mod user;
 | 
			
		||||
 | 
			
		||||
pub trait TableMeta<'a>: for<'r> sqlx::FromRow<'r, PgRow> {
 | 
			
		||||
    type PrimaryKey: Encode<'a, super::CurrDb> + Type<super::CurrDb> + Clone;
 | 
			
		||||
pub trait TableMeta: for<'r> sqlx::FromRow<'r, PgRow> {
 | 
			
		||||
    type PrimaryKey: Type<super::CurrDb> + Clone;
 | 
			
		||||
    const TABLE: &'static str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone, Default)]
 | 
			
		||||
pub struct ForeignKey<'a, FK: TableMeta<'a>> {
 | 
			
		||||
pub struct ForeignKey<FK: TableMeta> {
 | 
			
		||||
    id: FK::PrimaryKey,
 | 
			
		||||
    _ft: PhantomData<FK>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, FK: TableMeta<'a> + Send + for<'r> sqlx::FromRow<'r, PgRow> + Unpin + 'a>
 | 
			
		||||
    ForeignKey<'a, FK>
 | 
			
		||||
{
 | 
			
		||||
    pub async fn extract(&self, db: &super::CurrPool) -> anyhow::Result<FK> {
 | 
			
		||||
impl<'a, FK: TableMeta + Send + for<'r> sqlx::FromRow<'r, PgRow> + Unpin + 'a> ForeignKey<FK> {
 | 
			
		||||
    pub async fn extract(&self, db: &super::CurrPool) -> anyhow::Result<FK>
 | 
			
		||||
    where
 | 
			
		||||
        <FK as TableMeta>::PrimaryKey: for<'b> sqlx::Encode<'b, super::CurrDb>,
 | 
			
		||||
    {
 | 
			
		||||
        let id = self.id.clone();
 | 
			
		||||
 | 
			
		||||
        let res = QueryBuilder::new("")
 | 
			
		||||
| 
						 | 
				
			
			@ -40,39 +41,44 @@ impl<'a, FK: TableMeta<'a> + Send + for<'r> sqlx::FromRow<'r, PgRow> + Unpin + '
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, TM: TableMeta<'a>> Type<super::CurrDb> for ForeignKey<'a, TM> {
 | 
			
		||||
impl<'a, TM: TableMeta> Type<super::CurrDb> for ForeignKey<TM> {
 | 
			
		||||
    fn type_info() -> <super::CurrDb as sqlx::Database>::TypeInfo {
 | 
			
		||||
        TM::PrimaryKey::type_info()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, TM: TableMeta<'a>> Decode<'a, super::CurrDb> for ForeignKey<'a, TM>
 | 
			
		||||
impl<'a, TM: TableMeta> Decode<'a, super::CurrDb> for ForeignKey<TM>
 | 
			
		||||
where
 | 
			
		||||
    &'a str: Decode<'a, super::CurrDb>,
 | 
			
		||||
    <TM as TableMeta<'a>>::PrimaryKey: sqlx::Decode<'a, super::CurrDb>,
 | 
			
		||||
    <TM as TableMeta>::PrimaryKey: sqlx::Decode<'a, super::CurrDb>,
 | 
			
		||||
{
 | 
			
		||||
    fn decode(
 | 
			
		||||
        value: <super::CurrDb as sqlx::Database>::ValueRef<'a>,
 | 
			
		||||
    ) -> Result<Self, Box<dyn Error + 'static + Send + Sync>> {
 | 
			
		||||
        <TM::PrimaryKey as Decode<super::CurrDb>>::decode(value);
 | 
			
		||||
        todo!()
 | 
			
		||||
        match <TM::PrimaryKey as Decode<super::CurrDb>>::decode(value) {
 | 
			
		||||
            Ok(v) => Ok(Self {
 | 
			
		||||
                id: v,
 | 
			
		||||
                _ft: PhantomData,
 | 
			
		||||
            }),
 | 
			
		||||
            Err(e) => Err(e),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, TM: TableMeta<'a>> Deref for ForeignKey<'a, TM> {
 | 
			
		||||
impl<TM: TableMeta> Deref for ForeignKey<TM> {
 | 
			
		||||
    type Target = TM::PrimaryKey;
 | 
			
		||||
    fn deref(&self) -> &Self::Target {
 | 
			
		||||
        &self.id
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, TM: TableMeta<'a>> DerefMut for ForeignKey<'a, TM> {
 | 
			
		||||
impl<TM: TableMeta> DerefMut for ForeignKey<TM> {
 | 
			
		||||
    fn deref_mut(&mut self) -> &mut Self::Target {
 | 
			
		||||
        &mut self.id
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a, FK: TableMeta<'a, PrimaryKey = i64>> From<i64> for ForeignKey<'a, FK> {
 | 
			
		||||
impl<FK: TableMeta<PrimaryKey = i64>> From<i64> for ForeignKey<FK> {
 | 
			
		||||
    fn from(value: FK::PrimaryKey) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            id: value,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,20 +7,20 @@ use crate::db::{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
pub struct AwardRecord<'a> {
 | 
			
		||||
pub struct AwardRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub award_id: ForeignKey<'a, Award>,
 | 
			
		||||
    pub author_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
    pub award_id: ForeignKey<Award>,
 | 
			
		||||
    pub author_id: ForeignKey<User>,
 | 
			
		||||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> TableMeta<'a> for AwardRecord<'a> {
 | 
			
		||||
impl TableMeta for AwardRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_awards";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl AwardRecord<'_> {
 | 
			
		||||
impl AwardRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            AwardRecord,
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +37,7 @@ impl AwardRecord<'_> {
 | 
			
		|||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
 | 
			
		||||
        self.author_id.extract(pool);
 | 
			
		||||
        let user = self.author_id.extract(pool).await?;
 | 
			
		||||
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,20 +7,20 @@ use crate::db::{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
pub struct MissionRecord<'a> {
 | 
			
		||||
pub struct MissionRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub mission_id: ForeignKey<'a, Mission>,
 | 
			
		||||
    pub author_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
    pub mission_id: ForeignKey<Mission>,
 | 
			
		||||
    pub author_id: ForeignKey<User>,
 | 
			
		||||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for MissionRecord<'_> {
 | 
			
		||||
impl TableMeta for MissionRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_missions";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl MissionRecord<'_> {
 | 
			
		||||
impl MissionRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            MissionRecord,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,20 +7,20 @@ use crate::db::{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
pub struct QualificationRecord<'a> {
 | 
			
		||||
pub struct QualificationRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub author_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub qualification_id: ForeignKey<'a, Qualification>,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
    pub author_id: ForeignKey<User>,
 | 
			
		||||
    pub qualification_id: ForeignKey<Qualification>,
 | 
			
		||||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> TableMeta<'a> for QualificationRecord<'a> {
 | 
			
		||||
impl TableMeta for QualificationRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_qualifications";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> QualificationRecord<'a> {
 | 
			
		||||
impl QualificationRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            QualificationRecord,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,20 +7,20 @@ use crate::db::{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
pub struct RankRecord<'a> {
 | 
			
		||||
pub struct RankRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub rank_id: ForeignKey<'a, Rank>,
 | 
			
		||||
    pub author_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
    pub rank_id: ForeignKey<Rank>,
 | 
			
		||||
    pub author_id: ForeignKey<User>,
 | 
			
		||||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> TableMeta<'a> for RankRecord<'a> {
 | 
			
		||||
impl TableMeta for RankRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_ranks";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> RankRecord<'a> {
 | 
			
		||||
impl RankRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            RankRecord,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,20 +7,20 @@ use crate::db::{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
pub struct TrainingRecord<'a> {
 | 
			
		||||
pub struct TrainingRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub training_id: ForeignKey<'a, Training>,
 | 
			
		||||
    pub author_id: ForeignKey<'a, User>,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
    pub training_id: ForeignKey<Training>,
 | 
			
		||||
    pub author_id: ForeignKey<User>,
 | 
			
		||||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> TableMeta<'a> for TrainingRecord<'a> {
 | 
			
		||||
impl TableMeta for TrainingRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_trainings";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> TrainingRecord<'a> {
 | 
			
		||||
impl TrainingRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            TrainingRecord,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,7 @@ pub struct Session {
 | 
			
		|||
    pub expires: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for Session {
 | 
			
		||||
impl TableMeta for Session {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "sessions";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ pub struct User {
 | 
			
		|||
    pub rank_id: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta<'_> for User {
 | 
			
		||||
impl TableMeta for User {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "users";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user