vika.rust

👋 Introduce

🦀 rust for vikadata api. To use this crate, it's good for you to understand some vikadata's concept. for example, space, node, datasheet, view, field, record and soon. You can go here, it's vika office produce manual.

Vikadata is a Commercial version of Open Source APITable which added full enterprise-ready features. Vikadata is the on-line visual database. It means that we can save structured data to vikadata by vikadata api, when we want to make some interesting and fun tools. Instead of using heavy database.

🚀 Using

🌌 Firstly, adding vika_community crate to your dependence.

```toml

Cargo.toml

[dependencies] vika_community = "0.1.2"

or

vika_community = { git = "https://github.com/y-t99/vika.rust.git" }

serde_json = "1.0" ```

🌠 Importing the crate, and create the vika_client by your vikadata's token.

```rust use vika_community::*;

let vikaclient: VIKAClient= VIKAClient::new("yourtoken".to_string()); ```

🪐 Querying your all spaces.

rust let spaces: Vec<Space> = vika_client.spaces.query_all().unwrap(); for space in spaces { println!( "the space's id is {} and name is {}. you {} are the space's admin", space.id, space.name, space.is_admin ); }

☁️ You can get the space's all nodes, and query one node's detail information.

rust let space_id = "spcXxx".to_string(); let node_id = "nodXxx".to_string(); // the space's all nodes let nodes: Vec<Node> = vika_client .spaces.space(&space_id) .nodes.query_all() .unwrap(); for node in nodes { println!( "the node info [id: {}, name: {}, type: {}, icon: {}, isFav: {}]. \nthe node's children is: {:?}", node.id, node.name, node.node_type, node.icon, node.is_fav, node.children ); } // the specified node let node: Node = vika_client .spaces.space(&space_id) .nodes.node(&node_id) .unwrap(); println!( "the node info: id: {}, name {}, type {}, icon {}, isFav {} \n. the node's children is: {:?}", node.id, node.name, node.node_type, node.icon, node.is_fav, node.children )

🌈 The datasheet's field manager.

```rust use serde_json::Value;

let spaceid = "spcXxx".tostring(); let datasheetid = "dstXxx".tostring(); let fields = vikaclient .spaces.space(&spaceid) .datasheets.datasheet(&datasheetid) .fields; // the new field info let fieldpostreq = PostFieldReq::builder() .name("name".tostring()) .assingletextreq() .defaultvalue("defaultvalue".tostring()) .build(); // the datasheet append the new field let newfield: PostFieldResp = fields.post(fieldpostreq).unwrap(); // query the datasheet's all fields info let fieldsvalue: Vec = fields.queryall().unwrap(); for fieldvalue in fieldsvalue { for fieldvalue in fieldsvalue { println!( "the field info [id: {}, name: {}, type: {}] \n the field's property: [{}].", fieldvalue["id"], fieldvalue["name"], fieldvalue["type"], fieldvalue["property"] ); } } // delete field by the field's id fields.fieldid(&new_field.id).delete(); ```

☄️ We can crete the datasheet.

rust let space_id = "spaceXxx".to_string(); let datasheets = vika_client.spaces.space(&space_id).datasheets; let field_post_req = PostFieldReq::builder() .name("field_name".to_string()) .as_single_text_req() .default_value("default_value".to_string()) .build(); let datasheet_post_req: PostDatasheetReq = PostDatasheetReq::builder() .name("datasheet_name".to_string()) .description("description".to_string()) .folder_id("fodXxx".to_string()) .pre_node_id("dstXxx".to_string()) .fields(vec![field_post_req]) .build(); let new_datasheet: PostDatasheetsResp = datasheets.post(datasheet_post_req).unwrap();

✨ Query the datasheet's record.

rust let space_id = "spcXxx".to_string(); let datasheet_id= "dstXxx".to_string(); let records = vika_client .spaces.space(&space_id) .datasheets.datasheet(&datasheet_id) .records; let records_req = GetRecordsReq::builder() .page_size(1) .max_records(1) .page_num(1) .field_key(FieldID::ID) .sort(vec![ ("fldXxx".to_string(), Sort::DESC) ]) .filter_by_formula("formula".to_string()) .build(); let records_resp: GetRecordsResp = records.query(records_req).unwrap(); println!( "the records' page [current page number.: {}, the page's record size: {}, total number of records that met filter: {}]. \n records: [{:?}]", records_resp.page_num, records_resp.page_size, records_resp.total, records_resp.records )

🛸 Managing the records.

rust // add records let filed_map = vec![ "fldXxx".to_string(), "fldYyy".to_string(), "fldZzz".to_string(), ]; let record = RecordMap::builder() .put_string(&filed_map[0], "value".to_string()) .put_strings(&filed_map[1], vec!["value".to_string()]) .build(); let post_records_req = PostRecordsReq::builder() .field_key(FieldID::ID) .records(vec![record]) .build(); let post_records_resp: PostRecordsResp = records.post(post_records_req).unwrap(); let record_id = post_records_resp.records[0].record_id.clone(); // update records let record: RecordMap = RecordMap::builder() .record_id(record_id.clone()) .put_string(&filed_map[2], "value".to_string()) .build(); let patch_records_req: PatchRecordsReq = PatchRecordsReq::builder() .field_key(FieldID::ID) .records(vec![record]) .build(); // delete records records.delete(vec![record_id.clone()]);

🚚 Waiting & Expecting

🛠️. more manager: view manager

👣. better error reporting

💪. more robust low-level code

🛹. easier API

🦀. more rust