reentrada/src/objects.rs

33 lines
1.1 KiB
Rust
Raw Normal View History

2022-09-12 20:47:35 +02:00
use crate::models::*;
use diesel::prelude::*;
use crate::database::establish_connection;
2022-09-08 19:13:08 +02:00
2022-09-12 20:47:35 +02:00
//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)
}
2022-09-08 19:13:08 +02:00
2022-09-12 20:47:35 +02:00
// 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)
}
2022-09-08 19:13:08 +02:00
2022-09-12 20:47:35 +02:00
//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();
2022-09-08 19:13:08 +02:00
object
2022-09-12 20:47:35 +02:00
.filter(location_tag.eq(pegatina))
.filter(nombre.eq(nome))
.first(conn)
2022-09-08 19:13:08 +02:00
}