Skip to content

Commit

Permalink
✨ can create cult and person (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy-lmao authored and James Holman committed Jan 23, 2020
1 parent 94ffceb commit da5503e
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 12 deletions.
144 changes: 144 additions & 0 deletions api/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion api/src/models/cult.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::Cult;
use crate::types::{Cult, NewCult};
use crate::db::get_db_conn;

pub fn get_cult_all(vec: &mut Vec<Cult>) {
Expand All @@ -25,3 +25,18 @@ pub fn get_cult_by_id(vec: &mut Vec<Cult>, id: i32) {
vec.push(cult);
}
}

pub fn create_cult(data: NewCult) -> Cult {
let conn = get_db_conn();
let res = &conn
.query(
"INSERT INTO cults (name) VALUES ($1) RETURNING id, name;",
&[&data.name],
)
.unwrap();
let row = res.iter().next().unwrap();
Cult {
id: row.get(0),
name: row.get(1),
}
}
Loading

0 comments on commit da5503e

Please sign in to comment.