query_example.rs 926 字节
Newer Older
B
Bo Ding 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
use libtaos::*;

fn taos_connect() -> Result<Taos, Error> {
    TaosCfgBuilder::default()
        .ip("localhost")
        .user("root")
        .pass("taosdata")
        .db("power")
        .port(6030u16)
        .build()
        .expect("TaosCfg builder error")
        .connect()
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    let taos = taos_connect().expect("connect error");
    let result = taos.query("SELECT ts, current FROM meters LIMIT 2").await?;
    // print column names
    let meta: Vec<ColumnMeta> = result.column_meta;
    for column in meta {
        print!("{}\t", column.name)
    }
    println!();
    // print rows
    let rows: Vec<Vec<Field>> = result.rows;
    for row in rows {
        for field in row {
            print!("{}\t", field);
        }
        println!();
    }
    Ok(())
}

// stdout:
// ts      current
// 2022-03-28 09:56:51.249 10.3
// 2022-03-28 09:56:51.749 12.6