wrap for ceresdb-client-rs
use example :
```rust use csdb::{connbyenv, Db, SQL}; use lazystatic::lazystatic;
lazystatic! { pub static ref DB: Db = connbyenv("CERESDBGRPC").unwrap(); pub static ref SQLDROPTEST: SQL = DB.sql(["test"], "DROP TABLE test");
// ctime 是用户记录创建时间
// ts 是写入时间
pub static ref SQL_TEST: SQL = DB.sql(["test"], 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', enablettl='false' )"#); pub static ref SQLINSERT: SQL = DB.sql(["test"], "INSERT INTO test (ts,uid,tag) VALUES ({},{},{})"); pub static ref SQLSELECT: SQL = DB.sql(["test"], "SELECT * FROM test"); // pub static ref SQLDELETE: SQL = DB.sql(["test"], "DELETE FROM test WHERE ts={} AND uid={}"); }
async fn main() -> anyhow::Result<()> { loginit::init();
let _ = SQLDROPTEST.exe(()).await; SQLTEST.exe(()).await?; SQLINSERT.exe((1, 2, "test")).await?; SQL_INSERT.exe((2, 2, "\'\"\r\n")).await?;
let li = SQLSELECT.li(()).await?; asserteq!(li.len(), 2); for i in li { dbg!(i); } // SQL_DELETE.exe([1, 3]).await?; Ok(()) } ```
output:
``` Finished test [unoptimized + debuginfo] target(s) in 0.08s Running tests/test.rs (/Users/z/wac.tax/rsrv/target/debug/deps/test-642162e92c721e87)
running 1 test INFO csdb: 10ms 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: 3ms INSERT INTO test (ts,uid,tag) VALUES (1,2,'test') INFO csdb: 7ms INSERT INTO test (ts,uid,tag) VALUES (2,2,'\'"\r\n') INFO csdb: 5ms 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.04s ```
in this output
INFO csdb: 4ms INSERT INTO test (ts,uid,tag) VALUES (1,2,'test')
means cost 4ms for this query