blob: dffe4fd79682d4f34bd556a21b609585fffdd977 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use diesel::prelude::*;
use crate::schema::maps;
#[derive(Insertable)]
#[table_name = "maps"]
pub struct NewMap<'a> {
pub name: &'a str,
pub file_path: &'a str,
}
#[derive(Queryable, Clone, Debug)]
pub struct Map {
pub id: i32,
pub name: String,
pub file_path: String,
}
pub fn create_map(new_map: NewMap, conn: &PgConnection) -> QueryResult<Map> {
diesel::insert_into(maps::table)
.values(new_map)
.get_result(conn)
}
pub fn find_map(id: i32, conn: &PgConnection) -> QueryResult<Map> {
maps::table.find(id).get_result(conn)
}
pub fn find_map_by_name(name: &str, conn: &PgConnection) -> QueryResult<Map> {
maps::table.filter(maps::name.eq(name)).first(conn)
}
pub fn list_maps(conn: &PgConnection) -> QueryResult<Vec<Map>> {
maps::table.get_results(conn)
}
|