extern crate r2d2; use std::{thread, io::Read}; use r2d2_postgres::{postgres::{NoTls, GenericClient, SimpleQueryRow, SimpleQueryMessage}, PostgresConnectionManager}; fn main() { let manager = PostgresConnectionManager::new( "host=127.0.0.1 port=5433 user=postgres password=postgres".parse().unwrap(), NoTls, ); let pool = r2d2::Pool::new(manager).unwrap(); let mut client = pool.get().unwrap(); let x:Vec<r2d2_postgres::postgres::SimpleQueryMessage> = client.simple_query("select * from hzfc limit 1").unwrap(); // let x = client.execute("select * from hzfc limit 1").unwrap(); for mm in x{ match mm { SimpleQueryMessage::CommandComplete(x) => { println!("{:?}", x); }, SimpleQueryMessage::Row(x) => { let tmpcode = x.body.buffer().to_vec(); println!("{:?}", String::from_utf8(tmpcode)); // println!("{:?}", tmpcode); }, _=> panic!("n") } } }
标签:postgresql,SimpleQueryMessage,unwrap,tmpcode,r2d2,let,postgres From: https://www.cnblogs.com/pythonClub/p/16745231.html