-
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
20 changed files
with
243 additions
and
208 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
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,16 @@ | ||
extern crate postgres; | ||
use crate::db::get_db_conn; | ||
use crate::type_defs::Cult; | ||
|
||
pub fn get_cult_all() -> Vec<Cult> { | ||
let mut vec = Vec::new(); | ||
let conn = get_db_conn(); | ||
for row in &conn.query("SELECT id, name, cult FROM cults", &[]).unwrap() { | ||
let cult = Cult { | ||
id: row.get(0), | ||
name: row.get(1), | ||
}; | ||
vec.push(cult); | ||
} | ||
vec | ||
} |
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,24 +1,28 @@ | ||
use crate::type_defs::{Cult, NewCult}; | ||
|
||
pub mod get_cult_by_id; | ||
pub mod create_cult; | ||
pub mod get_cult_all; | ||
pub mod get_cult_by_id; | ||
use get_cult_by_id::{get_loader, CultLoader}; | ||
|
||
#[derive(Clone)] | ||
pub struct CultData { | ||
cult_by_id: CultLoader, | ||
cult_by_id: CultLoader, | ||
} | ||
|
||
impl CultData { | ||
pub fn new() -> CultData { | ||
CultData { | ||
cult_by_id: get_loader(), | ||
pub fn new() -> CultData { | ||
CultData { | ||
cult_by_id: get_loader(), | ||
} | ||
} | ||
pub async fn cult_by_id(&self, id: i32) -> Cult { | ||
self.cult_by_id.load(id).await.unwrap() | ||
} | ||
} | ||
pub async fn cult_by_id(&self, id: i32) -> Cult { | ||
self.cult_by_id.load(id).await.unwrap() | ||
} | ||
pub async fn create_cult(&self, data: NewCult) -> Cult { | ||
create_cult::create_cult(data) | ||
} | ||
} | ||
pub async fn create_cult(&self, data: NewCult) -> Cult { | ||
create_cult::create_cult(data) | ||
} | ||
pub async fn get_all_cults(&self) -> Vec<Cult> { | ||
get_cult_all::get_cult_all() | ||
} | ||
} |
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,5 +1,5 @@ | ||
mod person; | ||
mod cult; | ||
mod person; | ||
|
||
pub use cult::CultData; | ||
pub use person::PersonData; | ||
pub use cult::CultData; |
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,20 @@ | ||
extern crate postgres; | ||
use crate::db::get_db_conn; | ||
use crate::type_defs::Person; | ||
|
||
pub fn get_person_all() -> Vec<Person> { | ||
let mut vec = Vec::new(); | ||
let conn = get_db_conn(); | ||
for row in &conn | ||
.query("SELECT id, name, cult FROM persons", &[]) | ||
.unwrap() | ||
{ | ||
let person = Person { | ||
id: row.get(0), | ||
name: row.get(1), | ||
cult: row.get(2), | ||
}; | ||
vec.push(person); | ||
} | ||
vec | ||
} |
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,29 +1,33 @@ | ||
use crate::type_defs::{Person, NewPerson}; | ||
use crate::type_defs::{NewPerson, Person}; | ||
|
||
pub mod create_person; | ||
pub mod get_person_all; | ||
pub mod get_person_by_id; | ||
pub mod get_persons_by_cult_id; | ||
pub mod create_person; | ||
|
||
#[derive(Clone)] | ||
pub struct PersonData { | ||
person_by_id: get_person_by_id::PersonLoader, | ||
persons_by_cult_id: get_persons_by_cult_id::PersonsLoader, | ||
person_by_id: get_person_by_id::PersonLoader, | ||
persons_by_cult_id: get_persons_by_cult_id::PersonsLoader, | ||
} | ||
|
||
impl PersonData { | ||
pub fn new() -> PersonData { | ||
PersonData { | ||
person_by_id: get_person_by_id::get_loader(), | ||
persons_by_cult_id: get_persons_by_cult_id::get_loader(), | ||
pub fn new() -> PersonData { | ||
PersonData { | ||
person_by_id: get_person_by_id::get_loader(), | ||
persons_by_cult_id: get_persons_by_cult_id::get_loader(), | ||
} | ||
} | ||
pub async fn person_by_id(&self, id: i32) -> Person { | ||
self.person_by_id.load(id).await.unwrap() | ||
} | ||
pub async fn persons_by_cult_id(&self, id: i32) -> Vec<Person> { | ||
self.persons_by_cult_id.load(id).await.unwrap() | ||
} | ||
} | ||
pub async fn person_by_id(&self, id: i32) -> Person { | ||
self.person_by_id.load(id).await.unwrap() | ||
} | ||
pub async fn persons_by_cult_id(&self, id: i32) -> Vec<Person> { | ||
self.persons_by_cult_id.load(id).await.unwrap() | ||
} | ||
pub async fn create_person(&self, data: NewPerson) -> Person { | ||
create_person::create_person(data) | ||
} | ||
} | ||
pub async fn create_person(&self, data: NewPerson) -> Person { | ||
create_person::create_person(data) | ||
} | ||
pub async fn get_all_persons(&self) -> Vec<Person> { | ||
get_person_all::get_person_all() | ||
} | ||
} |
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
Oops, something went wrong.