Compare commits
3 Commits
bfbb458c4e
...
e2b183ddc6
Author | SHA1 | Date | |
---|---|---|---|
|
e2b183ddc6 | ||
|
739406336b | ||
|
5a0aa72066 |
@ -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;
|
||||||
|
19
src/demo.rs
19
src/demo.rs
@ -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");
|
||||||
|
@ -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?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user