Rust: PostgreSQL のデータを読む (Read)
4289 ワード
Cargo.toml
[package]
name = "postgres_read"
version = "0.1.0"
edition = "2018"
[dependencies]
postgres = "*"
src/main.rs
// --------------------------------------------------------------------
/*
postgres_read/src/main.rs
Jul/24/2020
*/
// --------------------------------------------------------------------
use postgres::{Client, NoTls, Error};
// --------------------------------------------------------------------
fn main() -> Result<(), Error> {
eprintln!("*** start ***");
let mut client = Client::connect("postgresql://scott:tiger123@localhost/city", NoTls)?;
for row in client.query("SELECT id,name,population,date_mod FROM cities", &[])? {
let id:String = row.get(0);
let name:String = row.get(1);
let population:i32 = row.get(2);
let date_mod:String = row.get(3);
println!("{}\t{}\t{}\t{}",id,name,population,date_mod);
};
eprintln!("*** end ***");
Ok(())
}
// --------------------------------------------------------------------
実行コマンド
cargo run
Author And Source
この問題について(Rust: PostgreSQL のデータを読む (Read)), 我々は、より多くの情報をここで見つけました https://qiita.com/ekzemplaro/items/243a26955673af09d899著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .