set database to absolute path
This commit is contained in:
parent
a47bb29e7d
commit
d1c8d66cca
4 changed files with 8 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ jobs:
|
|||
run: |
|
||||
cat > .env << EOF
|
||||
DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
|
||||
DATABASE_PATH=${{ secrets.DATABASE_PATH }}
|
||||
EOF
|
||||
chmod 600 .env
|
||||
|
||||
|
|
|
|||
|
|
@ -10,5 +10,6 @@ To do:
|
|||
|
||||
FAQ table
|
||||
- ID: Primary Key
|
||||
- Guild ID (Server ID): FK string
|
||||
- title: string
|
||||
- description: string
|
||||
|
|
@ -1,16 +1,15 @@
|
|||
use std::path::Path;
|
||||
use std::{env, path::Path};
|
||||
|
||||
// Using SQLite
|
||||
use rusqlite::{Connection, OpenFlags, Result};
|
||||
|
||||
pub fn init_db(filename: &str) -> Result<Connection, rusqlite::Error> {
|
||||
let filepath = Path::new(filename);
|
||||
pub fn init_db() -> Result<Connection, rusqlite::Error> {
|
||||
let filename = env::var("DATABASE_PATH").unwrap_or_else(|_| "bot_data.sqlite".to_string());
|
||||
let filepath = Path::new(&filename);
|
||||
|
||||
let open_flags = OpenFlags::default();
|
||||
|
||||
let conn = Connection::open_with_flags(filepath, open_flags);
|
||||
|
||||
conn
|
||||
Connection::open_with_flags(filepath, open_flags)
|
||||
}
|
||||
|
||||
fn table_exists(conn: &Connection, table_name: &str) -> Result<bool> {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ async fn main() {
|
|||
dotenv::dotenv().ok();
|
||||
|
||||
// SQLite
|
||||
let conn = init_db("bot_data.sqlite").expect("Failed to start database");
|
||||
let conn = init_db().expect("Failed to start database");
|
||||
init_tables(&conn).expect("Failed to init tables");
|
||||
let conn = Arc::new(Mutex::new(conn));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue