diff options
author | Vika <vika@fireburn.ru> | 2024-03-04 04:40:50 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-03-04 04:40:50 +0300 |
commit | efc10086cbb6726c3728c8edda93b8fd00436717 (patch) | |
tree | 749437e3a12181e5380a59e32b16fdbf78e87ba9 /src/database/postgres | |
parent | b7f0140dc05e4b33352e0ea46db4b36c6bfb2894 (diff) | |
download | kittybox-efc10086cbb6726c3728c8edda93b8fd00436717.tar.zst |
Support ?q=category queries
Warning, untested. But hopefully works!
Diffstat (limited to 'src/database/postgres')
-rw-r--r-- | src/database/postgres/mod.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/database/postgres/mod.rs b/src/database/postgres/mod.rs index ee7dd1c..71c4d58 100644 --- a/src/database/postgres/mod.rs +++ b/src/database/postgres/mod.rs @@ -75,6 +75,21 @@ impl PostgresStorage { #[async_trait::async_trait] impl Storage for PostgresStorage { #[tracing::instrument(skip(self))] + async fn categories(&self, url: &str) -> Result<Vec<String>> { + sqlx::query_scalar::<_, String>(" +SELECT jsonb_array_elements(mf2['properties']['category']) AS category +FROM kittybox.mf2_json +WHERE + jsonb_typeof(mf2['properties']['category']) = 'array' + AND uid LIKE ($1 + '%') + GROUP BY category ORDER BY count(*) DESC +") + .bind(url) + .fetch_all(&self.db) + .await + .map_err(|err| err.into()) + } + #[tracing::instrument(skip(self))] async fn post_exists(&self, url: &str) -> Result<bool> { sqlx::query_as::<_, (bool,)>("SELECT exists(SELECT 1 FROM kittybox.mf2_json WHERE uid = $1 OR mf2['properties']['url'] ? $1)") .bind(url) |