feat(db): add diesel and sqlite3 as dependencies
This commit is contained in:
parent
e4dfea45c5
commit
32b7632258
|
@ -1 +1,2 @@
|
|||
RUST_LOG =
|
||||
RUST_LOG=
|
||||
DATABASE_URL=
|
|
@ -13,5 +13,7 @@ members = ["server", "client"]
|
|||
uuid = { version = "^0.8", features = ["v4"] }
|
||||
twox-hash = "^1.6"
|
||||
thiserror = "^1.0"
|
||||
diesel = { version = "^1.4", features = ["sqlite"] }
|
||||
dotenv = "^0.15"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# For documentation on how to configure this file,
|
||||
# see diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/schema.rs"
|
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE game_file
|
|
@ -0,0 +1,8 @@
|
|||
-- Your SQL goes here
|
||||
CREATE TABLE game_file (
|
||||
id INTEGER PRIMARY KEY,
|
||||
original_path BLOB NOT NULL, -- TEXT assumes a Unicode Encoding
|
||||
file_hash INTEGER NOT NULL, -- u64, but that's not
|
||||
game_save_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (game_save_id) REFERENCES game_save_location (id)
|
||||
)
|
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE game_save_location
|
|
@ -0,0 +1,7 @@
|
|||
-- Your SQL goes here
|
||||
CREATE TABLE game_save_location (
|
||||
id INTEGER PRIMARY KEY,
|
||||
friendly_name TEXT -- This can be null
|
||||
original_PATH BLOB NOT NULL,
|
||||
uuid BLOB NOT NULL
|
||||
)
|
|
@ -0,0 +1,14 @@
|
|||
use diesel::prelude::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
pub fn establish_connection() -> SqliteConnection {
|
||||
dotenv().ok();
|
||||
|
||||
// TODO: Consider whether it is best practice to panic here
|
||||
// or have establish_connection return a Result with a thiserror enum
|
||||
|
||||
let db_url = env::var("DATABASE_URL").expect("$DATABASE_URL was not set");
|
||||
SqliteConnection::establish(&db_url).expect(&format!("Error connecting to {}", db_url))
|
||||
}
|
|
@ -1,4 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
pub mod db;
|
||||
pub mod game;
|
||||
pub mod models;
|
||||
pub mod schema;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct GameFile {
|
||||
pub id: i32,
|
||||
pub original_path: PathBuf,
|
||||
pub file_hash: u64,
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
table! {
|
||||
game_file (id) {
|
||||
id -> Nullable<Integer>,
|
||||
original_path -> Binary,
|
||||
file_hash -> Integer,
|
||||
game_save_id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
game_save_location (id) {
|
||||
id -> Nullable<Integer>,
|
||||
friendly_name -> Text,
|
||||
uuid -> Binary,
|
||||
}
|
||||
}
|
||||
|
||||
joinable!(game_file -> game_save_location (game_save_id));
|
||||
|
||||
allow_tables_to_appear_in_same_query!(
|
||||
game_file,
|
||||
game_save_location,
|
||||
);
|
Loading…
Reference in New Issue