-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9de9bbf
commit 21f875b
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use rusqlite::Connection; | ||
|
||
pub fn create_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 | ||
)", | ||
[], | ||
).expect("Failed to create users table"); | ||
|
||
conn.execute( | ||
"CREATE TABLE IF NOT EXISTS category ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT NOT NULL | ||
)", | ||
[], | ||
).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) | ||
)", | ||
[], | ||
).expect("Failed to create homework_hub table"); | ||
|
||
log::info!("created database successfully!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters