From b7e85e8c69e7f996337a03a7f1ea7a81b26885a5 Mon Sep 17 00:00:00 2001 From: Arlo Filley Date: Sun, 6 Nov 2022 19:28:35 +0000 Subject: [PATCH] added a users table --- src/sql.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sql.rs b/src/sql.rs index 05b0968..733e526 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -7,6 +7,15 @@ fn get_connection() -> rusqlite::Connection { pub fn create_database() -> Result<()> { let connection = get_connection(); + + connection.execute( + "CREATE TABLE IF NOT EXISTS users ( + user_id INTEGER PRIMARY KEY, + username UNIQUE TEXT NOT NULL, + password TEXT NOT NULL + )", + () + )?; connection.execute( "CREATE TABLE IF NOT EXISTS tests ( @@ -18,9 +27,10 @@ pub fn create_database() -> Result<()> { quote_id INTEGER, wpm INTEGER, accuracy INTEGER, - user_id INTEGER + user_id INTEGER, + FOREIGN KEY(user_id) REFERENCES users(user_id) )", - (), // empty parameters list + () )?; Ok(())