首页 > 数据库 >r2d2-postgresql

r2d2-postgresql

时间:2022-09-30 16:11:39浏览次数:52  
标签:postgresql SimpleQueryMessage unwrap tmpcode r2d2 let postgres

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

相关文章