Skip to content

Commit

Permalink
chore: correct table name, update license, remove unused code
Browse files Browse the repository at this point in the history
chore: remove code to ensure buildability

fix: merge comflicts
  • Loading branch information
nezutero committed Feb 19, 2024
1 parent d099cc2 commit 8194640
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 46 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "hh"
version = "0.1.0"
edition = "2021"
authors = ["github.com/DmitroPodolsky", "github.com/geekenji"]
description = "Centralized platform to manage and access your university homework information."
license = "MIT"
repository = "github.com/seadclub/hh.git"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
65 changes: 19 additions & 46 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,37 @@ use rusqlite::{Connection, Error};
use crate::models::MyDialogue;

pub fn create_db() {
let conn = Connection::open("hh.db").expect("Failed to establish connection to db");
let conn = Connection::open("your_database.db").expect("Failed to open database");

conn.execute(
"CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT
)",
id INTEGER PRIMARY KEY AUTOINCREMENT
)",
[],
)
.expect("Failed to create users table");
).expect("Failed to create users table");

conn.execute(
"CREATE TABLE IF NOT EXISTS category (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
)",
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
)",
[],
)
.expect("Failed to create category table");
).expect("Failed to create category table");

conn.execute(
"CREATE TABLE IF NOT EXISTS homework (
name TEXT PRIMARY KEY,
desc TEXT NOT NULL,
deadline DATE,
date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
category_id INTEGER,
user_id INTEGER,
FOREIGN KEY (category_id) REFERENCES category(id),
FOREIGN KEY (user_id) REFERENCES users(id)
)",
"CREATE TABLE IF NOT EXISTS homework_hub (
name TEXT PRIMARY KEY,
desc TEXT NOT NULL,
deadline DATE,
date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
category_id INTEGER,
user_id INTEGER,
FOREIGN KEY (category_id) REFERENCES category(id),
FOREIGN KEY (user_id) REFERENCES users(id)
)",
[],
)
.expect("Failed to create homework_hub table");
).expect("Failed to create homework_hub table");

<<<<<<< HEAD
log::info!("created database successfully!");
}

Expand Down Expand Up @@ -106,27 +102,4 @@ pub fn insert_homework(name: &str, desc: &str, deadline: &str, category_id: &i32
)?;

Ok(())
=======
log::info!("DB created successfully!");
>>>>>>> 37cdce1 (chore: format code)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_create_db_and_insert() {
create_db();
let conn = Connection::open("hh.db").expect("Failed to open database");
conn.execute("INSERT INTO users DEFAULT VALUES", [])
.expect("Failed to insert into users");
conn.execute("INSERT INTO category (name) VALUES (?)", ["test"])
.expect("Failed to insert into category");
conn.execute(
"INSERT INTO homework_hub (name, desc, deadline, category_id, user_id) VALUES (?, ?, ?, ?, ?)",
["test", "test", "2021-12-12", "1", "1"],
)
.expect("Failed to insert into hh.db");
}
}

0 comments on commit 8194640

Please sign in to comment.