Compare commits

...

3 Commits

Author SHA1 Message Date
Greg Shuflin
e2b183ddc6 Add ACX substack demo 2025-02-03 20:47:59 -08:00
Greg Shuflin
739406336b Get rid of problematic sql verification 2025-02-03 20:44:20 -08:00
Greg Shuflin
5a0aa72066 Use categorizations 2025-02-03 20:29:20 -08:00
3 changed files with 18 additions and 13 deletions

View File

@ -9,11 +9,6 @@ BEGIN
WHEN NOT ( WHEN NOT (
json_valid(NEW.categorization) json_valid(NEW.categorization)
AND json_type(NEW.categorization) = 'array' AND json_type(NEW.categorization) = 'array'
AND (
SELECT COUNT(*)
FROM json_each(NEW.categorization)
WHERE json_type(value) != 'text'
) = 0
) )
THEN RAISE(ROLLBACK, 'categorization must be an array of strings') THEN RAISE(ROLLBACK, 'categorization must be an array of strings')
END; END;
@ -26,11 +21,6 @@ BEGIN
WHEN NOT ( WHEN NOT (
json_valid(NEW.categorization) json_valid(NEW.categorization)
AND json_type(NEW.categorization) = 'array' AND json_type(NEW.categorization) = 'array'
AND (
SELECT COUNT(*)
FROM json_each(NEW.categorization)
WHERE json_type(value) != 'text'
) = 0
) )
THEN RAISE(ROLLBACK, 'categorization must be an array of strings') THEN RAISE(ROLLBACK, 'categorization must be an array of strings')
END; END;

View File

@ -1,5 +1,6 @@
use chrono; use chrono;
use sqlx; use sqlx;
use rocket::serde;
use uuid::Uuid; use uuid::Uuid;
use crate::feeds::Feed; use crate::feeds::Feed;
@ -69,11 +70,25 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
); );
isidore.categorization = vec!["Webcomic".to_string()]; isidore.categorization = vec!["Webcomic".to_string()];
let feeds = [bbc_news, xkcd, isidore]; let mut acx = Feed::new(
"Astral Codex Ten".to_string(),
"https://www.astralcodexten.com/feed".parse().unwrap(),
demo_id,
);
acx.categorization = vec!["Substack".to_string()];
let feeds = [bbc_news, xkcd, isidore, acx];
for feed in feeds { for feed in feeds {
// TODO: This insert logic is substantially the same as Feed::write_to_database. // TODO: This insert logic is substantially the same as Feed::write_to_database.
// Should find a way to unify these two code paths to avoid duplication. // Should find a way to unify these two code paths to avoid duplication.
let categorization_json = serde::json::to_value(feed.categorization).map_err(|e| {
eprintln!("Failed to serialize categorization: {}", e);
sqlx::Error::Decode(Box::new(e))
}).unwrap();
println!("{}", categorization_json);
sqlx::query( sqlx::query(
"INSERT INTO feeds (feed_id, name, url, user_id, added_time, last_checked_time, categorization) "INSERT INTO feeds (feed_id, name, url, user_id, added_time, last_checked_time, categorization)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, json(?7))", VALUES (?1, ?2, ?3, ?4, ?5, ?6, json(?7))",
@ -84,7 +99,7 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
.bind(feed.user_id.to_string()) .bind(feed.user_id.to_string())
.bind(feed.added_time.to_rfc3339()) .bind(feed.added_time.to_rfc3339())
.bind(feed.last_checked_time.to_rfc3339()) .bind(feed.last_checked_time.to_rfc3339())
.bind("[]") // empty categorization array as JSON .bind(categorization_json.to_string())
.execute(pool) .execute(pool)
.await .await
.expect("Failed to create demo feed"); .expect("Failed to create demo feed");

View File

@ -52,7 +52,7 @@ impl Feed {
.bind(self.user_id.to_string()) .bind(self.user_id.to_string())
.bind(self.added_time.to_rfc3339()) .bind(self.added_time.to_rfc3339())
.bind(self.last_checked_time.to_rfc3339()) .bind(self.last_checked_time.to_rfc3339())
.bind(&categorization_json.to_string()) .bind(categorization_json.to_string())
.execute(&mut **db) .execute(&mut **db)
.await?; .await?;