lugares e obxetos na base de datos

This commit is contained in:
serxoz 2022-09-12 20:52:19 +02:00
parent 497339ab30
commit 50958b0d26
3 changed files with 64 additions and 0 deletions

13
src/database.rs Normal file
View File

@ -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))
}

22
src/models.rs Normal file
View File

@ -0,0 +1,22 @@
use diesel::prelude::*;
#[derive(Queryable)]
pub struct RLocation {
pub tag: String,
pub nombre: Option<String>,
pub descripcion: String,
pub salida_norte: Option<String>,
pub salida_sur: Option<String>,
pub salida_este: Option<String>,
pub salida_oeste: Option<String>,
pub salida_arriba: Option<String>,
pub salida_abajo: Option<String>,
}
#[derive(Queryable)]
pub struct RObject {
pub tag: String,
pub nombre: Option<String>,
pub descripcion: String,
pub location_tag: String,
}

29
src/schema.rs Normal file
View File

@ -0,0 +1,29 @@
// @generated automatically by Diesel CLI.
diesel::table! {
location (tag) {
tag -> Varchar,
nombre -> Nullable<Varchar>,
descripcion -> Varchar,
salida_norte -> Nullable<Varchar>,
salida_sur -> Nullable<Varchar>,
salida_este -> Nullable<Varchar>,
salida_oeste -> Nullable<Varchar>,
salida_arriba -> Nullable<Varchar>,
salida_abajo -> Nullable<Varchar>,
}
}
diesel::table! {
object (tag) {
tag -> Varchar,
nombre -> Nullable<Varchar>,
descripcion -> Varchar,
location_tag -> Varchar,
}
}
diesel::allow_tables_to_appear_in_same_query!(
location,
object,
);