-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
72 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
use crate::type_defs::{Cult,NewCult}; | ||
use crate::db::get_db_conn; | ||
|
||
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
use crate::type_defs::{Person,NewPerson}; | ||
use crate::db::get_db_conn; | ||
|
||
pub fn create_person(data: NewPerson) -> Person { | ||
let conn = get_db_conn(); | ||
let res = &conn | ||
.query( | ||
"INSERT INTO persons (name, cult) VALUES ($1, $2) RETURNING id, name, cult;", | ||
&[&data.name, &data.cult], | ||
) | ||
.unwrap(); | ||
let row = res.iter().next().unwrap(); | ||
Person { | ||
id: row.get(0), | ||
name: row.get(1), | ||
cult: row.get(2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
use super::schema::Context; | ||
use crate::type_defs::{Cult, NewCult, NewPerson, Person}; | ||
use juniper::FieldResult; | ||
|
||
pub struct Mutation; | ||
|
||
#[juniper::graphql_object(Context = Context)] | ||
impl Mutation { | ||
// not really needed, but graphiql bug if this is empty… | ||
pub fn nothing(_name: String) -> i32 { | ||
0 | ||
pub async fn create_person(ctx: &Context, data: NewPerson) -> FieldResult<Person> { | ||
Ok(ctx.person_data.create_person(data).await) | ||
} | ||
} | ||
pub async fn create_cult(ctx: &Context, data: NewCult) -> FieldResult<Cult> { | ||
Ok(ctx.cult_data.create_cult(data).await) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters