5个版本
0.1.5 | 2023年6月23日 |
---|---|
0.1.4 | 2023年6月23日 |
0.1.2 | 2023年6月23日 |
0.1.1 | 2023年6月23日 |
0.1.0 | 2023年6月23日 |
#115 in #wrap
每月30次下载
45KB
770 行
csdb
ceresdb-client-rs的封装
使用示例
use csdb::{conn_by_env, Db, SQL};
use lazy_static::lazy_static;
lazy_static! {
pub static ref DB: Db = conn_by_env("CERESDB_GRPC").unwrap();
pub static ref SQL_DROP_TEST: SQL = DB.sql("DROP TABLE test");
// ctime 是用户记录创建时间
// ts 是写入时间
pub static ref SQL_TEST: SQL = DB.sql(r#"CREATE TABLE test (
ts TIMESTAMP NOT NULL,
uid uint64 NOT NULL,
tag string NOT NULL,
TIMESTAMP KEY(ts),
PRIMARY KEY(uid, ts)
) ENGINE=Analytic WITH (
compression='ZSTD',
enable_ttl='false'
)"#);
pub static ref SQL_INSERT: SQL = DB.sql("INSERT INTO test (ts,uid,tag) VALUES ({},{},{})");
pub static ref SQL_SELECT: SQL = DB.sql("SELECT * FROM test");
// pub static ref SQL_DELETE: SQL = DB.sql(["test"], "DELETE FROM test WHERE ts={} AND uid={}");
}
#[tokio::main]
#[test]
async fn main() -> anyhow::Result<()> {
loginit::init();
let _ = SQL_DROP_TEST.exe(()).await;
SQL_TEST.exe(()).await?;
SQL_INSERT.exe((1, 2, "test")).await?;
SQL_INSERT.exe((2, 2, "\'\"\r\n")).await?;
let li = SQL_SELECT.li(()).await?;
assert_eq!(li.len(), 2);
for i in li {
dbg!(i);
}
// SQL_DELETE.exe([1, 3]).await?;
Ok(())
}
输出
Compiling csdb v0.1.4 (/Users/z/wac.tax/rsrv/csdb)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running tests/test.rs (/Users/z/wac.tax/rsrv/target/debug/deps/test-de4776b8ba9c98fe)
running 1 test
INFO csdb: 12ms DROP TABLE test
INFO csdb: 3ms CREATE TABLE test (
ts TIMESTAMP NOT NULL,
uid uint64 NOT NULL,
tag string NOT NULL,
TIMESTAMP KEY(ts),
PRIMARY KEY(uid, ts)
) ENGINE=Analytic WITH (
compression='ZSTD',
enable_ttl='false'
)
INFO csdb: 2ms INSERT INTO test (ts,uid,tag) VALUES (1,2,'test')
INFO csdb: 1ms INSERT INTO test (ts,uid,tag) VALUES (2,2,'\'"\r\n')
INFO csdb: 3ms SELECT * FROM test
[csdb/tests/test.rs:38] i = Row {
columns: [
Column {
name: "uid",
value: UInt64(
2,
),
},
Column {
name: "ts",
value: Timestamp(
1,
),
},
Column {
name: "tag",
value: String(
"test",
),
},
],
}
[csdb/tests/test.rs:38] i = Row {
columns: [
Column {
name: "uid",
value: UInt64(
2,
),
},
Column {
name: "ts",
value: Timestamp(
2,
),
},
Column {
name: "tag",
value: String(
"'\"\r\n",
),
},
],
}
test main ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s
此输出中的
INFO csdb: 4ms INSERT INTO test (ts,uid,tag) VALUES (1,2,'test')
表示此查询耗时4ms
依赖项
~20–31MB
~431K SLoC