diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-25 20:14:50 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-25 20:14:50 +0200 |
commit | f727613efb790dd927062c342f3cf16dd09e54c3 (patch) | |
tree | 8ab7903d18998c31fa7c80ceac902595f7ec8acf | |
parent | aa066ef5bb9ed043feafd0e87e219cb34cce35c5 (diff) | |
download | planetwars.dev-f727613efb790dd927062c342f3cf16dd09e54c3.tar.xz planetwars.dev-f727613efb790dd927062c342f3cf16dd09e54c3.zip |
create db::maps module
-rw-r--r-- | planetwars-server/src/db/maps.rs | 31 | ||||
-rw-r--r-- | planetwars-server/src/db/mod.rs | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/planetwars-server/src/db/maps.rs b/planetwars-server/src/db/maps.rs new file mode 100644 index 0000000..c9f50a0 --- /dev/null +++ b/planetwars-server/src/db/maps.rs @@ -0,0 +1,31 @@ +use diesel::{PgConnection, QueryDsl, QueryResult, RunQueryDsl}; + +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 list_maps(conn: &PgConnection) -> QueryResult<Vec<Map>> { + maps::table.get_results(conn) +}
\ No newline at end of file diff --git a/planetwars-server/src/db/mod.rs b/planetwars-server/src/db/mod.rs index 84ed2a6..f014cea 100644 --- a/planetwars-server/src/db/mod.rs +++ b/planetwars-server/src/db/mod.rs @@ -1,4 +1,5 @@ pub mod bots; +pub mod maps; pub mod matches; pub mod ratings; pub mod sessions; |