Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
nezutero committed Feb 19, 2024
1 parent 301915c commit d51249b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,41 @@ use rusqlite::{Connection, Error};
use crate::models::MyDialogue;

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

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_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)
)",
"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)
)",
[],
).expect("Failed to create homework_hub table");
)
.expect("Failed to create homework_hub table");

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

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

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

0 comments on commit d51249b

Please sign in to comment.