aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/db/maps.rs
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-server/src/db/maps.rs')
-rw-r--r--planetwars-server/src/db/maps.rs35
1 files changed, 35 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..dffe4fd
--- /dev/null
+++ b/planetwars-server/src/db/maps.rs
@@ -0,0 +1,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)
+}