Rust 操作 PostgreSQL 数据库 常用操作:
一、插入数据-INSERT INTO
extern crate postgres;
use postgres::{Connection, SslMode};
fn main() {
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
conn.execute("INSERT INTO user (username) VALUES (\"test\")", &[]).unwrap();
}
二、数据查询 - SELECT
extern crate postgres;
use postgres::{Connection, SslMode};
fn main() {
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
for row in &conn.query("SELECT * FROM user", &[]).unwrap();
println!("Found person {}", row.get(0));
}
}