summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/db.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-09 15:47:22 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-09 15:47:22 -0800
commit9ca31fd3713ed9bcf1e1eb601c022afcb4fc4d74 (patch)
tree3b2e4a2e23789871a53c4109c1fac7d1bd77cf15 /adenosine-pds/src/db.rs
parent7af51292ddfc81d55dd5beff07c557757bb0075f (diff)
downloadadenosine-9ca31fd3713ed9bcf1e1eb601c022afcb4fc4d74.tar.gz
adenosine-9ca31fd3713ed9bcf1e1eb601c022afcb4fc4d74.zip
pds: session.get and handle.resolve XRPC endpoints
Diffstat (limited to 'adenosine-pds/src/db.rs')
-rw-r--r--adenosine-pds/src/db.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/adenosine-pds/src/db.rs b/adenosine-pds/src/db.rs
index 051588d..b94689a 100644
--- a/adenosine-pds/src/db.rs
+++ b/adenosine-pds/src/db.rs
@@ -138,6 +138,32 @@ impl AtpDatabase {
Ok(did_maybe.map(|v| Did::from_str(&v).expect("valid DID in database")))
}
+ /// Looks up local account handle associated with a DID
+ ///
+ /// TODO: remote lookups, and/or local cache of external DIDs
+ pub fn resolve_did(&mut self, did: &Did) -> Result<Option<String>> {
+ let mut stmt = self
+ .conn
+ .prepare_cached("SELECT handle FROM account WHERE did = $1")?;
+ let handle_maybe: Option<String> = stmt
+ .query_row(params!(did.to_string()), |row| row.get(0))
+ .optional()?;
+ Ok(handle_maybe)
+ }
+
+ /// Looks up local DID associated with handle
+ ///
+ /// TODO: remote lookups, and/or local cache of external DIDs
+ pub fn resolve_handle(&mut self, handle: &str) -> Result<Option<Did>> {
+ let mut stmt = self
+ .conn
+ .prepare_cached("SELECT did FROM account WHERE handle = $1")?;
+ let did_maybe: Option<String> = stmt
+ .query_row(params!(handle), |row| row.get(0))
+ .optional()?;
+ Ok(did_maybe.map(|v| Did::from_str(&v).expect("valid DID in database")))
+ }
+
pub fn delete_session(&mut self, jwt: &str) -> Result<bool> {
let mut stmt = self
.conn