From 50958b0d2676600c9bdfc122b447bc25dd6db2ac Mon Sep 17 00:00:00 2001 From: serxoz Date: Mon, 12 Sep 2022 20:52:19 +0200 Subject: [PATCH] lugares e obxetos na base de datos --- src/database.rs | 13 +++++++++++++ src/models.rs | 22 ++++++++++++++++++++++ src/schema.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/database.rs create mode 100644 src/models.rs create mode 100644 src/schema.rs diff --git a/src/database.rs b/src/database.rs new file mode 100644 index 0000000..3a4d2a6 --- /dev/null +++ b/src/database.rs @@ -0,0 +1,13 @@ +use diesel::prelude::*; +use diesel::mysql::MysqlConnection; +use dotenv::dotenv; +use std::env; + +pub fn establish_connection() -> MysqlConnection { + dotenv().ok(); + + let database_url = env::var("DATABASE_URL") + .expect("DATABASE_URL must be set"); + MysqlConnection::establish(&database_url) + .expect(&format!("Error connecting to {}", database_url)) +} diff --git a/src/models.rs b/src/models.rs new file mode 100644 index 0000000..9bf1b02 --- /dev/null +++ b/src/models.rs @@ -0,0 +1,22 @@ +use diesel::prelude::*; + +#[derive(Queryable)] +pub struct RLocation { + pub tag: String, + pub nombre: Option, + pub descripcion: String, + pub salida_norte: Option, + pub salida_sur: Option, + pub salida_este: Option, + pub salida_oeste: Option, + pub salida_arriba: Option, + pub salida_abajo: Option, +} + +#[derive(Queryable)] +pub struct RObject { + pub tag: String, + pub nombre: Option, + pub descripcion: String, + pub location_tag: String, +} diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..59b7e58 --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,29 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + location (tag) { + tag -> Varchar, + nombre -> Nullable, + descripcion -> Varchar, + salida_norte -> Nullable, + salida_sur -> Nullable, + salida_este -> Nullable, + salida_oeste -> Nullable, + salida_arriba -> Nullable, + salida_abajo -> Nullable, + } +} + +diesel::table! { + object (tag) { + tag -> Varchar, + nombre -> Nullable, + descripcion -> Varchar, + location_tag -> Varchar, + } +} + +diesel::allow_tables_to_appear_in_same_query!( + location, + object, +);