reentrada/src/objects.rs

33 lines
1.1 KiB
Rust

use crate::models::*;
use diesel::prelude::*;
use crate::database::establish_connection;
//get_object trae da base de datos un obxeto pola sua pegatina
pub fn get_object(pegatina: String) -> Result<RObject, diesel::result::Error> {
use crate::schema::object::dsl::*;
let conn = &mut establish_connection();
object
.filter(tag.eq(pegatina))
.first(conn)
}
// get_objects trae da base de datos todos os obxetos de unha localización
pub fn get_objects(pegatina: String) -> Result<Vec<RObject>, diesel::result::Error> {
use crate::schema::object::dsl::*;
let conn = &mut establish_connection();
object
.filter(location_tag.eq(pegatina))
.get_results(conn)
}
//get_object_here trae da base de datos o obxeto polo nome e a pegatina da sala actual
pub fn get_object_here(pegatina: String, nome: String) -> Result<RObject, diesel::result::Error> {
use crate::schema::object::dsl::*;
let conn = &mut establish_connection();
object
.filter(location_tag.eq(pegatina))
.filter(nombre.eq(nome))
.first(conn)
}