diff --git a/Cargo.lock b/Cargo.lock index 89997b8..dbe12ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,10 +563,7 @@ dependencies = [ name = "db" version = "0.1.0" dependencies = [ - "async-trait", - "atproto", "sqlx", - "thiserror 2.0.12", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 9129ba7..908c860 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ resolver = "3" members = [ "api", "atproto","db", "ingestor"] [workspace.dependencies] -async-trait = "0.1.88" atproto = { path = "./atproto" } serde = "1.0.219" serde_json = "1.0.140" diff --git a/atproto/src/lib.rs b/atproto/src/lib.rs index 15a875a..21f8919 100644 --- a/atproto/src/lib.rs +++ b/atproto/src/lib.rs @@ -4,24 +4,14 @@ use core::str::FromStr; pub use atrium_api::types::{ Collection, string::{ - AtIdentifier as Authority, - Cid, - Datetime, - Did, Nsid, RecordKey, - Tid, - Handle, + AtIdentifier as Authority, } }; pub mod lexicons; -pub struct StrongRef { - pub content: T, - pub cid: Cid, -} - pub struct Uri { whole: String, // These fields could be useful in the future, diff --git a/db/Cargo.toml b/db/Cargo.toml index dd1d0b9..ded38de 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -4,8 +4,5 @@ version = "0.1.0" edition = "2024" [dependencies] -thiserror = "2.0.12" -atproto.workspace = true -async-trait.workspace = true sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio"] } -tokio.workspace = true +tokio = "1.45.0" diff --git a/db/src/connection.rs b/db/src/connection.rs index 1c66086..ba883cc 100644 --- a/db/src/connection.rs +++ b/db/src/connection.rs @@ -12,8 +12,8 @@ use sqlx::{ }; use std::string::ToString; -pub struct Db { - pool: Pool +pub struct Db { + pool: Pool } #[non_exhaustive] @@ -55,4 +55,45 @@ impl Db { Ok(Db { pool }) } // + // pub async fn add_user(&self, user: &User) -> Result<()> { + // query!(r#" + // INSERT INTO users(userdid, handle) VALUES ($1, $2) + // "#, + // user.userdid, user.handle + // ).execute(self.pool).await?; + // Ok(()) + // } + // + // pub async fn add_session(&self, session: &Session) -> Result<()> { + // let mut transaction = self.pool.begin().await?; + // + // query!(r#" + // INSERT INTO sessions(sessionuri, label) VALUES ($1, $2) + // "#, + // session.sessionuri, session.label + // ).execute(&mut *transaction).await?; + // + // for participant in session.participants { + // query!(r#" + // INSERT INTO participants(sessionuri, userdid, role) VALUES ($1, $2, $3) + // "#, + // session.sessionuri, participant.userdid, participant.role.to_string() + // ).execute(&mut *transaction).await?; + // } + // + // transaction.commit().await + // } + // + // pub async fn add_participant(&self, session: Session, + // participant: Participant) -> Result { + // query!(r#" + // INSERT INTO participants(sessionuri, userdid, role) VALUES ($1, $2, $3) + // "#, + // session.sessionuri, participant.userdid, participant.role.to_string() + // ).execute(self.pool).await?; + // + // session.participants.push(participant); + // + // Ok(session) + // } } diff --git a/db/src/interfaces.rs b/db/src/interfaces.rs new file mode 100644 index 0000000..d3629e1 --- /dev/null +++ b/db/src/interfaces.rs @@ -0,0 +1,15 @@ +use atproto::{ + Did, + Uri, +}; + +pub struct User { + userdid: Did, + handle: Handle, +} + +struct Participant { + participantdid: Did, + role: Role, +} + diff --git a/db/src/interfaces/mod.rs b/db/src/interfaces/mod.rs deleted file mode 100644 index d13ba36..0000000 --- a/db/src/interfaces/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod spoor; diff --git a/db/src/interfaces/spoor.rs b/db/src/interfaces/spoor.rs deleted file mode 100644 index 8f97b57..0000000 --- a/db/src/interfaces/spoor.rs +++ /dev/null @@ -1,137 +0,0 @@ -use crate::DbError; -use atproto::{ - Cid, - Datetime, - Did, - StrongRef, - Tid, - Handle, -}; -use sqlx::{ - PgTransaction, - PgPool, - query, -}; - -pub struct Activity { - pub authority: User, - pub key: Tid, - - pub cid: Option, - pub session: Option>, - pub progress: Option, - pub performed_at: Option, - pub created_at: Option, -} - -pub struct Session { - pub authority: User, - pub key: Tid, - - pub cid: Option, - pub content: Option>, - pub label: Option, - pub created_at: Option, - pub other_participants: Option>, -} - -pub struct User { - pub did: Did, - pub handle: Option, -} - -#[non_exhaustive] -pub enum Participant { - Owner(User), - Added(User), -} - -#[non_exhaustive] -pub enum Content { - UnknownContent -} - -#[non_exhaustive] -pub enum Progress { - UnknownProgress -} - -pub async fn ingest_session(db: PgPool, session: Session) -> Result<(), DbError> { - let mut transaction = db.begin().await?; - write_session(&mut transaction, session).await?; - transaction.commit().await.map_err(DbError::Backend) -} - -async fn write_session(tr: &mut PgTransaction<'_>, session: Session) -> Result<(), DbError> { - query!(r#" - INSERT INTO sessions(sessionuri, label, created_at, contenturi, contentcid) - "#).execute(&mut tr).await?; - Ok(()) -} - -// pub fn injest_activity(db: PgPool, activity: Activity) -> Result<(), Error> { -// todo!(); -// } -// -// let mut transaction = db.begin().await?; -// -// query!(r#" -// INSERT INTO sessions(sessionuri, label) VALUES ($1, $2) -// "#, -// session.sessionuri, session.label -// ).execute(&mut *transaction).await?; -// -// for participant in session.participants { -// query!(r#" -// INSERT INTO participants(sessionuri, userdid, role) VALUES ($1, $2, $3) -// "#, -// session.sessionuri, participant.userdid, participant.role.to_string() -// ).execute(&mut *transaction).await?; -// } -// -// transaction.commit().await -// } -// -// pub async fn ingest_participant(db: PgPool, participant: Participant) -> Result<(), Error> { -// query!(r#" -// INSERT INTO sessions(sessionuri, label) VALUES ($1, $2) -// "#, -// session.sessionuri, session.label -// ).execute(&mut *transaction).await?; -// -// for participant in session.participants { -// query!(r#" -// INSERT INTO participants(sessionuri, userdid, role) VALUES ($1, $2, $3) -// "#, -// session.sessionuri, participant.userdid, participant.role.to_string() -// ).execute(&mut *transaction).await?; -// } -// -// transaction.commit().await -// } -// - - // pub async fn add_user(&self, user: &User) -> Result<()> { - // query!(r#" - // INSERT INTO users(userdid, handle) VALUES ($1, $2) - // "#, - // user.userdid, user.handle - // ).execute(self.pool).await?; - // Ok(()) - // } - // - // pub async fn add_session(&self, session: &Session) -> Result<()> { - // } - // - // pub async fn add_participant(&self, session: Session, - // participant: Participant) -> Result { - // query!(r#" - // INSERT INTO participants(sessionuri, userdid, role) VALUES ($1, $2, $3) - // "#, - // session.sessionuri, participant.userdid, participant.role.to_string() - // ).execute(self.pool).await?; - // - // session.participants.push(participant); - // - // Ok(session) - // } diff --git a/db/src/lib.rs b/db/src/lib.rs index 30652a5..82e9c13 100644 --- a/db/src/lib.rs +++ b/db/src/lib.rs @@ -1,14 +1 @@ -use thiserror::Error; - -pub mod interfaces; - -#[non_exhaustive] -#[derive(Debug, Error)] -pub enum DbError { - #[error("Database Implementation Error: {0}")] - Backend(#[from] sqlx::Error), -} - - - -// pub struct db; +pub struct db; diff --git a/ingestor/Cargo.toml b/ingestor/Cargo.toml index 7da302c..a177581 100644 --- a/ingestor/Cargo.toml +++ b/ingestor/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" [dependencies] anyhow = "1.0.98" -async-trait.workspace = true +async-trait = "0.1.88" atproto.workspace = true rocketman = "0.2.0" serde.workspace = true