sqlite basic impl
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +1,3 @@
 | 
			
		||||
/target
 | 
			
		||||
/.idea
 | 
			
		||||
/todo-db.db3
 | 
			
		||||
							
								
								
									
										62
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										62
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -953,6 +953,18 @@ dependencies = [
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fallible-iterator"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fallible-streaming-iterator"
 | 
			
		||||
version = "0.1.9"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fast-srgb8"
 | 
			
		||||
version = "1.0.0"
 | 
			
		||||
@@ -984,6 +996,12 @@ dependencies = [
 | 
			
		||||
 "miniz_oxide",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "foldhash"
 | 
			
		||||
version = "0.1.4"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "font-types"
 | 
			
		||||
version = "0.7.3"
 | 
			
		||||
@@ -1323,6 +1341,18 @@ name = "hashbrown"
 | 
			
		||||
version = "0.15.2"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "foldhash",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hashlink"
 | 
			
		||||
version = "0.10.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "hashbrown 0.15.2",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hassle-rs"
 | 
			
		||||
@@ -1671,6 +1701,17 @@ dependencies = [
 | 
			
		||||
 "redox_syscall 0.5.8",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "libsqlite3-sys"
 | 
			
		||||
version = "0.31.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "ad8935b44e7c13394a179a438e0cebba0fe08fe01b54f152e29a93b5cf993fd4"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "cc",
 | 
			
		||||
 "pkg-config",
 | 
			
		||||
 "vcpkg",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "linux-raw-sys"
 | 
			
		||||
version = "0.4.15"
 | 
			
		||||
@@ -2535,6 +2576,20 @@ version = "0.20.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "rusqlite"
 | 
			
		||||
version = "0.33.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "1c6d5e5acb6f6129fe3f7ba0a7fc77bca1942cb568535e18e7bc40262baf3110"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bitflags 2.8.0",
 | 
			
		||||
 "fallible-iterator",
 | 
			
		||||
 "fallible-streaming-iterator",
 | 
			
		||||
 "hashlink",
 | 
			
		||||
 "libsqlite3-sys",
 | 
			
		||||
 "smallvec",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "rust-ini"
 | 
			
		||||
version = "0.18.0"
 | 
			
		||||
@@ -2984,6 +3039,7 @@ name = "todo-app"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "iced",
 | 
			
		||||
 "rusqlite",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
@@ -3129,6 +3185,12 @@ version = "0.2.6"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "vcpkg"
 | 
			
		||||
version = "0.2.15"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "version_check"
 | 
			
		||||
version = "0.9.5"
 | 
			
		||||
 
 | 
			
		||||
@@ -5,3 +5,4 @@ edition = "2021"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
iced = { version = "0.13.1"}
 | 
			
		||||
rusqlite = { version = "0.33.0", features = ["bundled"] }
 | 
			
		||||
							
								
								
									
										47
									
								
								src/db.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/db.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
use std::path::Path;
 | 
			
		||||
use rusqlite::{params, Connection, Result};
 | 
			
		||||
use crate::def;
 | 
			
		||||
use crate::def::Task;
 | 
			
		||||
 | 
			
		||||
pub(crate) fn startup(path: &Path) -> Result<(Connection)> {
 | 
			
		||||
    // let conn = Connection::open_in_memory()?;
 | 
			
		||||
    let conn = Connection::open(path)?;
 | 
			
		||||
    
 | 
			
		||||
    conn.execute(
 | 
			
		||||
        "CREATE TABLE IF NOT EXISTS tasks (
 | 
			
		||||
                id INTEGER PRIMARY KEY,
 | 
			
		||||
                checked INTEGER NOT NULL,
 | 
			
		||||
                value TEXT NOT NULL
 | 
			
		||||
        )",
 | 
			
		||||
        ()
 | 
			
		||||
    )?;
 | 
			
		||||
    
 | 
			
		||||
    // todo
 | 
			
		||||
    
 | 
			
		||||
    Ok(conn)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub(crate) fn get_tasks(conn: &Connection) -> Result<()> {
 | 
			
		||||
    let mut stmt = conn.prepare("SELECT checked, value FROM tasks")?;
 | 
			
		||||
    let task_iter = stmt.query_map([], |row| {
 | 
			
		||||
        Ok(Task {
 | 
			
		||||
            checked: row.get(0)?,
 | 
			
		||||
            value: row.get(1)?,
 | 
			
		||||
        })
 | 
			
		||||
    })?;
 | 
			
		||||
    
 | 
			
		||||
    for task in task_iter {
 | 
			
		||||
        println!("{:?}", task);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub(crate) fn insert_task(task: Task, conn: &Connection) -> Result<()> {
 | 
			
		||||
    conn.execute(
 | 
			
		||||
        "INSERT INTO tasks (checked, value) VALUES (?1, ?2)",
 | 
			
		||||
        (&task.checked, &task.value),
 | 
			
		||||
    )?;
 | 
			
		||||
    
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,9 @@
 | 
			
		||||
use iced::Event;
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
pub struct Task {
 | 
			
		||||
    pub(crate) checked: bool,
 | 
			
		||||
    pub(crate) value: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct TaskData {
 | 
			
		||||
    pub(crate) checked: bool,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,11 +1,15 @@
 | 
			
		||||
use std::path::Path;
 | 
			
		||||
use iced::window::Settings;
 | 
			
		||||
use iced::Size;
 | 
			
		||||
use def::Todo;
 | 
			
		||||
use crate::db::startup;
 | 
			
		||||
use crate::def::Task;
 | 
			
		||||
 | 
			
		||||
mod todo;
 | 
			
		||||
mod def;
 | 
			
		||||
mod db;
 | 
			
		||||
 | 
			
		||||
fn main() -> iced::Result {
 | 
			
		||||
/*fn main() -> iced::Result {
 | 
			
		||||
    let settings = Settings {
 | 
			
		||||
        size: Size::new(500.0, 600.0),
 | 
			
		||||
        resizable: false,
 | 
			
		||||
@@ -17,4 +21,18 @@ fn main() -> iced::Result {
 | 
			
		||||
        .theme(Todo::theme)
 | 
			
		||||
        .window(settings)
 | 
			
		||||
        .run()
 | 
			
		||||
}*/
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    let path: &Path = Path::new("./todo-db.db3");
 | 
			
		||||
    let conn = startup(path);
 | 
			
		||||
    let t = Task {
 | 
			
		||||
        checked: true,
 | 
			
		||||
        value: String::from("Troll Ink"),
 | 
			
		||||
    };
 | 
			
		||||
    let c = conn.unwrap();
 | 
			
		||||
    /*let r = db::insert_task(t, &c);
 | 
			
		||||
    println!("{:?}", r);*/
 | 
			
		||||
    
 | 
			
		||||
    let rr = db::get_tasks(&c);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user