this repo has no description
at main 844 B view raw
1use std::path::Path; 2 3use rusqlite::{Connection, Result}; 4 5pub fn init() -> Result<()> { 6 // Check if the database file exists, and create it if it doesn't 7 if !Path::new("db.sqlite3").exists() { 8 let db = Connection::open("db.sqlite3")?; 9 match db.execute( 10 "CREATE TABLE IF NOT EXISTS sessions ( 11 state TEXT NOT NULL, 12 access_token TEXT NOT NULL, 13 refresh_token TEXT NOT NULL, 14 last_validated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 15 UNIQUE(state, access_token) 16 )", 17 [], 18 ) { 19 Ok(_) => println!("Table 'sessions' created successfully."), 20 Err(e) => println!("Error creating table 'sessions': {}", e), 21 }; 22 } 23 Ok(()) 24}