Last active
March 31, 2016 03:45
-
-
Save ccjr/fc47ea0c855b325b3d21b06dcfe9bff3 to your computer and use it in GitHub Desktop.
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
// postgres = "0.11.5" | |
extern crate postgres; | |
use postgres::{Connection, SslMode}; | |
fn main() { | |
let conn = Connection::connect("postgres://foo:bar@localhost/playground", SslMode::None) | |
.unwrap(); | |
setup_db(&conn); | |
let sort = "id DESC"; | |
for row in &conn.query("SELECT id FROM foo ORDER BY $1", &[&sort]).unwrap() { | |
let id: i32 = row.get("id"); | |
println!("** ORDER BY {}: {}", &sort, id); | |
} | |
} | |
fn setup_db(conn: &Connection) { | |
let _ = conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]); | |
let _ = conn.execute("INSERT INTO foo VALUES (1)", &[]); | |
let _ = conn.execute("INSERT INTO foo VALUES (2)", &[]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment