-
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
4 changed files
with
63 additions
and
1 deletion.
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,29 @@ | ||
extern crate postgres; | ||
use postgres::{Connection, TlsMode}; | ||
use std::env; | ||
|
||
pub fn get_cult_all(vec: &mut Vec<crate::Cult>) { | ||
let pg_connection_string = env::var("DATABASE_URI").expect("need a db uri"); | ||
println!("Connecting to {}", pg_connection_string); | ||
let conn = Connection::connect(&pg_connection_string[..], TlsMode::None) .unwrap(); | ||
println!("Connection is fine"); | ||
for row in &conn.query("SELECT id, name FROM cults", &[]).unwrap() { | ||
let cult = crate::Cult { | ||
id: row.get(0), | ||
name: row.get(1) | ||
}; | ||
vec.push(cult); | ||
} | ||
} | ||
|
||
pub fn get_cult_by_id(vec: &mut Vec<crate::Cult>, id: i32) { | ||
let pg_connection_string = env::var("DATABASE_URI").expect("need a db uri"); | ||
let conn = Connection::connect(&pg_connection_string[..], TlsMode::None) .unwrap(); | ||
for row in &conn.query("SELECT id, name FROM cults WHERE id = $1", &[&id]).unwrap() { | ||
let cult = crate::Cult { | ||
id: row.get(0), | ||
name: row.get(1) | ||
}; | ||
vec.push(cult); | ||
} | ||
} |
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,10 @@ | ||
CREATE TABLE cults | ||
( | ||
id serial NOT NULL, | ||
name VARCHAR(100) | ||
); | ||
|
||
-- ALTER TABLE CULTS owner TO jayylmao; | ||
|
||
INSERT INTO cults (name) | ||
VALUES ('Church of the Latter day dudes'); |
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