Author: qians Date: 2022/5/1 WasmVersion: 1.0.0
```rust let req = Request::project("project") .table("table") .create() .createone(serdejson::json!({ "t-name": "h", "t-age": 10 })) .createone(serdejson::json!({ "t-name": "hhh", "t-age": 10 })) .done() .to_string();
let reqj = serdejson::json!({ "auth": 2, "project": "project", "table": "table", "data":[ { "t-name": "h", "t-age": 10 }, { "t-name": "hhh", "t-age": 10 } ] }) .tostring(); assert_eq!(req, reqj) ```
```rust let req = Request::project("project") .table("table") .get("2") .addfields(&[String::from("t-name"), String::from("t-age")]) .done() .tostring();
let reqj = serdejson::json!({ "auth": 2, "project": "project", "table": "table", "fields": ["t-name", "t-age"], "id": "2" }) .tostring(); assert_eq!(req, reqj) ```
```rust let req = Request::project("project") .table("table") .set("2") .done(serdejson::json!({ "t-name": "h", "t-age": 10 })) .tostring();
let reqj = serdejson::json!({ "auth": 2, "project": "project", "table": "table", "id": "2", "data": { "t-name": "h", "t-age": 10 } }) .tostring(); assert_eq!(req, reqj) ```
```rust let req = Request::project("project") .table("table") .query( Query::new() .and() .gt("t-id", 1) .and() .query(Query::new().and().lt("t-id", 1).or().eq("t-id", "qians")), ) .desc("t-id") .addfield("t-id") .addfield("t-name") .setpagination(1, 4) .done() .tostring();
let reqj = serdejson::json!({ "auth": 2, "project": "project", "table": "table", "conditions": { "pagination": { "page": 1, "pageSize": 4 }, "order": { "t-id": "desc" }, "fields": ["t-id", "t-name"], "query": { "and": [ {"range": {"t-id": {"gt": 1}}}, {"query": { "and": [ {"range": {"t-id": {"lt": 1}}} ], "or": [ {"match": {"t-id": "qians"}} ] }} ] } } }) .tostring(); assert_eq!(req, reqj); ```
```rust let req = Request::project("project") .table("table") .updatebyquery(Query::new().and().eq("id", "2")) .done(serdejson::json!({ "t-name": "hhh", "t-age": 10 })) .tostring();
let qv = serdejson::json!({ "auth": 2, "project": "project", "table": "table", "query": { "and": [ {"match": {"id": "2"}} ] }, "data": { "t-name": "hhh", "t-age": 10 } }) .tostring(); assert_eq!(req, qv); ```
```rust
struct A {
a: i32,
b: String,
c: bool,
d: Option
let a = A { a: 1, b: String::from("1"), c: true, d: Some(String::from("1")), }; let v = vec![a.clone(), a.clone(), a.clone()];
let json = serdejson::json!({ "error": "", "count": 3, "data": [ { "a": 1, "b": "1", "c": true, "d": "1", }, { "a": 1, "b": "1", "c": true, "d": "1", }, { "a": 1, "b": "1", "c": true, "d": "1", } ] }) .tostring(); let res: Response = Response::from_str(&json).unwrap(); let res: Vec = res.into().unwrap();
assert_eq!(v, res) ```