do all db stuff in one shot
This commit is contained in:
parent
dbfc7409c3
commit
6bfbf6ad0a
2 changed files with 97 additions and 28 deletions
124
server/src/db.rs
124
server/src/db.rs
|
@ -3,7 +3,100 @@ use leptos::*;
|
|||
use serde::*;
|
||||
use sqlx::*;
|
||||
|
||||
pub async fn db_build(pool: &SqlitePool) -> Result<(), ServerFnError> {
|
||||
// pub async fn db_build(pool: &SqlitePool) -> Result<(), ServerFnError> {
|
||||
// let _res = query(
|
||||
// "
|
||||
// CREATE TABLE
|
||||
// blog (
|
||||
// content_type TEXT,
|
||||
// title TEXT,
|
||||
// date TEXT,
|
||||
// content TEXT
|
||||
// )
|
||||
// ",
|
||||
// )
|
||||
// .execute(pool)
|
||||
// .await?;
|
||||
//
|
||||
// // println!("{:?}", _res);
|
||||
//
|
||||
// #[derive(Deserialize)]
|
||||
// struct ArticleFrontmatter {
|
||||
// content_type: String,
|
||||
// title: String,
|
||||
// date: String,
|
||||
// }
|
||||
//
|
||||
// for file in std::fs::read_dir("./public/blog".to_string())? {
|
||||
// let fileinfo = file?;
|
||||
// let filepath = fileinfo.path();
|
||||
//
|
||||
// if let Some(filetype) = filepath.extension() {
|
||||
// if filetype == "md" {
|
||||
// let file = std::fs::read_to_string(filepath)?;
|
||||
// let html_from_md =
|
||||
// femark::process_markdown_to_html_with_frontmatter(&file.to_string(), true)
|
||||
// .expect("Problem processing markdown");
|
||||
// let content = html_from_md.content;
|
||||
// let _toc = html_from_md.toc;
|
||||
//
|
||||
// if let Some(front_raw) = html_from_md.frontmatter {
|
||||
// if let Some(front_code) = front_raw.code_block {
|
||||
// let toml: ArticleFrontmatter = toml::from_str(&front_code.source)?;
|
||||
//
|
||||
// let article = Article {
|
||||
// content_type: toml.content_type,
|
||||
// title: toml.title,
|
||||
// date: toml.date,
|
||||
// content,
|
||||
// };
|
||||
//
|
||||
// let _res = sqlx::query(
|
||||
// "
|
||||
// INSERT INTO
|
||||
// blog (content_type, title, date, content)
|
||||
// VALUES
|
||||
// ($1, $2, $3, $4)
|
||||
// ",
|
||||
// )
|
||||
// .bind(article.content_type)
|
||||
// .bind(article.title)
|
||||
// .bind(article.date)
|
||||
// .bind(article.content)
|
||||
// .execute(pool)
|
||||
// .await?;
|
||||
//
|
||||
// // println!("{:?}", _res);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
pub async fn start_pool() -> Result<SqlitePool, ServerFnError> {
|
||||
println!(
|
||||
"
|
||||
⠄⠄⠄⠄⢀⡤⣖⣞⣮⢾⢽⣳⢯⢿⢷⣦⣄⠄⠄⠐⠄
|
||||
⠐⠄⠄⣴⣯⣯⢷⣻⣺⢽⣫⢾⣝⡵⡯⣾⣽⢷⣄⠄⠄
|
||||
⠄⢀⣼⢿⡽⣾⢯⣷⣻⣽⢽⣳⣳⢽⡺⡮⣫⢯⢿⣦⠄
|
||||
⠄⣼⣿⢽⡯⣿⡽⣾⡿⣞⣯⢷⢯⢯⢯⢯⡺⡪⡳⣻⠄
|
||||
⣴⣿⣿⣽⣟⣷⣟⣯⣿⡽⣞⣯⢿⡽⡽⡵⣝⢮⣫⣺⠄
|
||||
⠄⠄⠉⠉⠛⠛⠛⠛⠛⠻⠿⠿⠿⣿⣿⡿⣿⣽⣾⣾⡀
|
||||
⠐⡀⠢⠄⡀⠄⢀⣄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⠣
|
||||
⡀⠂⠈⣪⣌⡤⢾⠿⠕⢤⣤⣨⣠⢤⠡⠄⠄⡌⠄⡐⡐
|
||||
⠐⠈⠄⠱⣻⡻⠶⢦⠶⠯⠟⢟⢯⢳⢩⡂⡆⡇⡐⡐⢌
|
||||
⢁⠐⠄⠈⣾⣓⢝⣛⡛⡗⣞⣗⢕⡕⢕⠕⡸⡀⠂⠌⡂
|
||||
⡀⠂⡁⠄⡿⣕⢷⣻⢽⢝⢞⢮⢳⠑⠅⢑⢜⠜⣬⢐⢈
|
||||
⠄⢁⣀⣴⠋⠪⠳⠹⠵⠹⠘⠈⠂⠁⡐⡸⡘⣠⡳⡣⣪
|
||||
⣽⢟⣿⡣⠄⢸⡄⠠⠠⡠⢠⢐⠨⡐⣴⣹⡨⣞⣎⢎⢺
|
||||
⠏⠟⠛⠃⠄⠘⠛⠊⠊⠘⠐⠅⠇⠻⠛⠓⠛⠛⠪⠓⠹
|
||||
db goin up"
|
||||
);
|
||||
let pool = SqlitePool::connect("sqlite::memory:").await?;
|
||||
|
||||
let _res = query(
|
||||
"
|
||||
CREATE TABLE
|
||||
|
@ -15,7 +108,7 @@ pub async fn db_build(pool: &SqlitePool) -> Result<(), ServerFnError> {
|
|||
)
|
||||
",
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
// println!("{:?}", _res);
|
||||
|
@ -63,7 +156,7 @@ pub async fn db_build(pool: &SqlitePool) -> Result<(), ServerFnError> {
|
|||
.bind(article.title)
|
||||
.bind(article.date)
|
||||
.bind(article.content)
|
||||
.execute(pool)
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
// println!("{:?}", _res);
|
||||
|
@ -73,28 +166,5 @@ pub async fn db_build(pool: &SqlitePool) -> Result<(), ServerFnError> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_pool() -> Result<SqlitePool, ServerFnError> {
|
||||
println!(
|
||||
"
|
||||
⠄⠄⠄⠄⢀⡤⣖⣞⣮⢾⢽⣳⢯⢿⢷⣦⣄⠄⠄⠐⠄
|
||||
⠐⠄⠄⣴⣯⣯⢷⣻⣺⢽⣫⢾⣝⡵⡯⣾⣽⢷⣄⠄⠄
|
||||
⠄⢀⣼⢿⡽⣾⢯⣷⣻⣽⢽⣳⣳⢽⡺⡮⣫⢯⢿⣦⠄
|
||||
⠄⣼⣿⢽⡯⣿⡽⣾⡿⣞⣯⢷⢯⢯⢯⢯⡺⡪⡳⣻⠄
|
||||
⣴⣿⣿⣽⣟⣷⣟⣯⣿⡽⣞⣯⢿⡽⡽⡵⣝⢮⣫⣺⠄
|
||||
⠄⠄⠉⠉⠛⠛⠛⠛⠛⠻⠿⠿⠿⣿⣿⡿⣿⣽⣾⣾⡀
|
||||
⠐⡀⠢⠄⡀⠄⢀⣄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⠣
|
||||
⡀⠂⠈⣪⣌⡤⢾⠿⠕⢤⣤⣨⣠⢤⠡⠄⠄⡌⠄⡐⡐
|
||||
⠐⠈⠄⠱⣻⡻⠶⢦⠶⠯⠟⢟⢯⢳⢩⡂⡆⡇⡐⡐⢌
|
||||
⢁⠐⠄⠈⣾⣓⢝⣛⡛⡗⣞⣗⢕⡕⢕⠕⡸⡀⠂⠌⡂
|
||||
⡀⠂⡁⠄⡿⣕⢷⣻⢽⢝⢞⢮⢳⠑⠅⢑⢜⠜⣬⢐⢈
|
||||
⠄⢁⣀⣴⠋⠪⠳⠹⠵⠹⠘⠈⠂⠁⡐⡸⡘⣠⡳⡣⣪
|
||||
⣽⢟⣿⡣⠄⢸⡄⠠⠠⡠⢠⢐⠨⡐⣴⣹⡨⣞⣎⢎⢺
|
||||
⠏⠟⠛⠃⠄⠘⠛⠊⠊⠘⠐⠅⠇⠻⠛⠓⠛⠛⠪⠓⠹
|
||||
db goin up"
|
||||
);
|
||||
|
||||
Ok(SqlitePool::connect("sqlite::memory:").await?)
|
||||
Ok(pool)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ async fn main() {
|
|||
let routes = generate_route_list(App);
|
||||
|
||||
let pool = start_pool().await.expect("pool error");
|
||||
let _ = db_build(&pool).await.expect("build error");
|
||||
|
||||
let app = Router::new()
|
||||
.leptos_routes_with_context(
|
||||
|
|
Loading…
Add table
Reference in a new issue