Added new models + establish_connection function

This commit is contained in:
Keanu D?lle 2020-02-04 23:53:24 +01:00
parent 5039fa32db
commit d78e4bd988
9 changed files with 37 additions and 9 deletions

View File

@ -0,0 +1,8 @@
use crate::helper::settings::Settings;
use diesel::{Connection, PgConnection};
use rocket::State;
pub fn establish_connection(settings: State<Settings>) -> PgConnection {
let db_url = settings.database.connection_string.clone();
PgConnection::establish(&db_url).expect(&format!("Error connecting to database."))
}

View File

@ -0,0 +1 @@
pub mod connector;

2
src/database/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod controller;
pub mod model;

View File

View File

@ -0,0 +1,6 @@
use diesel::pg::types::sql_types::Uuid;
#[derive(Queryable)]
pub struct Entity {
entity_id: Uuid,
}

View File

View File

@ -0,0 +1,4 @@
pub mod addresses;
pub mod entities;
pub mod members;
pub mod users;

View File

View File

@ -7,8 +7,12 @@ extern crate serde_derive;
#[macro_use]
extern crate log;
extern crate lazy_static;
#[macro_use] extern crate rocket;
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate diesel;
pub mod database;
pub mod helper;
pub mod modules;
@ -18,14 +22,17 @@ use rocket::State;
fn main() {
env_logger::init(); //Initializes logger. Set environment variable RUST_LOG=debug|info|warn|error to set loglevel
let settings = match Settings::new(){
Ok(settings) => settings,
Err(e) => {
error!("Failed to read config: {}", e);
std::process::exit(1);
}
let settings = match Settings::new() {
Ok(settings) => settings,
Err(e) => {
error!("Failed to read config: {}", e);
std::process::exit(1);
}
};
debug!("Hello, world! Default Language: {}", settings.application.default_language);
debug!(
"Hello, world! Default Language: {}",
settings.application.default_language
);
rocket::ignite().manage(settings);
}
}