WIP: Fetch all tasks
This commit is contained in:
parent
a8e3a44816
commit
535f332a81
@ -1,6 +1,7 @@
|
||||
// use indexmap::IndexMap;
|
||||
// use int_enum::IntEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::SqlitePool;
|
||||
use std::cmp::min;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
@ -16,8 +17,7 @@ pub struct Column {
|
||||
pub tasks: Vec<Task>,
|
||||
}
|
||||
|
||||
// #[derive(Deserialize, Serialize, Debug, Clone, Copy)]
|
||||
#[derive(Default, Deserialize, Serialize, Debug)]
|
||||
#[derive(Default, Deserialize, Serialize, Debug, sqlx::FromRow)]
|
||||
pub struct Task {
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
@ -68,6 +68,7 @@ impl Default for TaskState<'_> {
|
||||
|
||||
pub struct State<'a> {
|
||||
pub project: Project,
|
||||
pub db_pool: SqlitePool,
|
||||
pub quit: bool,
|
||||
pub columns: Vec<Column>,
|
||||
pub task_edit_state: Option<TaskState<'a>>,
|
||||
@ -75,10 +76,11 @@ pub struct State<'a> {
|
||||
|
||||
impl State<'_> {
|
||||
#[must_use]
|
||||
pub fn new(project: Project) -> Self {
|
||||
pub fn new(db_pool: SqlitePool, project: Project) -> Self {
|
||||
State {
|
||||
quit: false,
|
||||
task_edit_state: None,
|
||||
db_pool,
|
||||
project,
|
||||
columns: vec![],
|
||||
}
|
||||
|
13
src/db.rs
Normal file
13
src/db.rs
Normal file
@ -0,0 +1,13 @@
|
||||
use sqlx::SqlitePool;
|
||||
use crate::app::Task;
|
||||
|
||||
pub async fn get_all_tasks(pool: SqlitePool) -> Option<Vec<Task>> {
|
||||
sqlx::query_as!(Task,
|
||||
r#"
|
||||
select title, description from task
|
||||
"#
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.ok()
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
mod app;
|
||||
mod input;
|
||||
mod ui;
|
||||
mod db;
|
||||
|
||||
pub use app::*;
|
||||
pub use db::*;
|
||||
pub use input::handle;
|
||||
pub use ui::draw;
|
||||
|
16
src/main.rs
16
src/main.rs
@ -87,21 +87,9 @@ async fn main() -> anyhow::Result<(), Box<dyn Error>> {
|
||||
}
|
||||
};
|
||||
|
||||
let pool = SqlitePool::connect("sqlite:db.sqlite").await?;
|
||||
let db_pool = SqlitePool::connect("sqlite:db.sqlite").await?;
|
||||
|
||||
let stuff = sqlx::query!(
|
||||
r#"
|
||||
select * from kanban
|
||||
"#
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.await?;
|
||||
|
||||
for item in stuff {
|
||||
println!("{} - {} - {}", item.id, item.name, item.description);
|
||||
}
|
||||
|
||||
let mut state = State::new(Project::load(filepath, &file)?);
|
||||
let mut state = State::new(db_pool, Project::load(filepath, &file)?);
|
||||
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = io::stdout();
|
||||
|
Loading…
x
Reference in New Issue
Block a user