8 个版本

0.2.2 2022 年 5 月 21 日
0.2.1 2022 年 4 月 7 日
0.2.0 2021 年 8 月 29 日
0.1.4 2020 年 8 月 23 日
0.1.1 2019 年 10 月 7 日

#665Web 编程

Download history 3/week @ 2024-03-04 30/week @ 2024-03-11 18/week @ 2024-03-18 51/week @ 2024-04-01 9/week @ 2024-04-08 5/week @ 2024-04-22 11/week @ 2024-04-29 10/week @ 2024-05-06 5/week @ 2024-05-13 12/week @ 2024-05-20 17/week @ 2024-05-27 37/week @ 2024-06-10 31/week @ 2024-06-17

每月 85 次下载

MIT 许可证

41KB
976

crate-name at crates.io crate-name at docs.rs Rust

Rustforce

Rust 的 Salesforce 客户端

用法

use rustforce::{Client, Error};
use rustforce::response::{QueryResponse, ErrorResponse};
use serde::Deserialize;
use std::env;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Account {
    #[serde(rename = "attributes")]
    attributes: Attribute,
    id: String,
    name: String,
}

#[derive(Deserialize, Debug)]
struct Attribute {
    url: String,
    #[serde(rename = "type")]
    sobject_type: String,
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    
    let client_id = env::var("SFDC_CLIENT_ID").unwrap();
    let client_secret = env::var("SFDC_CLIENT_SECRET").unwrap();
    let username = env::var("SFDC_USERNAME").unwrap();
    let password = env::var("SFDC_PASSWORD").unwrap();

    let mut client = Client::new(client_id, client_secret);
    client.login_with_credential(username, password).await?;

    let res: QueryResponse<Account> = client.query("SELECT Id, Name FROM Account WHERE id = '0012K00001drfGYQAY'".to_string()).await?;
    println!("{:?}", res);

    Ok(())
}

身份验证

用户名密码流程

let mut client = Client::new(client_id, client_secret);
client.login_with_credential(username, password).await?;

[WIP]授权代码授予

刷新令牌

let r = client.refresh("xxxx").await?;

查询记录

let r: Result<QueryResponse<Account>, Error> = client.query("SELECT Id, Name FROM Account").await?;

查询所有记录

let r: Result<QueryResponse<Account>, Error> = client.query_all("SELECT Id, Name FROM Account").await?;

通过 ID 查找

let r: Result<Account, Error> = client.find_by_id("Account", "{sf_id}").await?;

创建记录

let mut params = HashMap::new();
params.insert("Name", "hello rust");
let r = client.create("Account", params).await?;
println!("{:?}", r);

更新记录

let r = client.update("Account", "{sobject_id}", params).await?;

更新/插入记录

let r = client.upsert("Account", "{external_key_name}", "{external_key", params).await?;

删除记录

let r = client.destroy("Account", "{sobject_id}").await?;

描述全局

let r = client.describe_global().await?;

描述 SObject

let r = client.describe("Account").await?;

版本

let versions = client.versions().await?;

搜索(SOSL)

let r = client.search("FIND {Rust}").await?;

依赖项

~6–21MB
~297K SLoC