pb-sdk

Crates.iopb-sdk
lib.rspb-sdk
version0.5.0
sourcesrc
created_at2024-10-26 21:38:54.879453
updated_at2024-10-28 20:47:46.454885
descriptionunofficial async pocketbase sdk
homepage
repository
max_upload_size
id1424174
size16,698
(awaprim)

documentation

README

installation:

cargo add pb-sdk

or add to cargo.toml

[dependencies]
pb-sdk = "0.5.0"

example usage:

use pb_sdk::{PbAdminClient, GetListSuccess};
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct Post {
    id: String,
    name: String,
    content: String
}
#[derive(Serialize)]
struct CreatePost {
    name: String,
    content: String
}


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>>{
        // authenticate
        let client = PbAdminClient::new("http://localhost:8090").auth_with_password("admin_username@example.com", "admin_password").await?;
        // list posts
        let posts: GetListSuccess<Post> = client.collection("posts").unwrap().get_list(1, 50).call().await?;
        // view post
        let post: Post = client.collection("posts").unwrap().get_one("s42mpy041qkmnzp").call().await?;
        // create post
        let new_post = CreatePost {
            name: "wood".to_string(),
            content: "yes".to_string()
        };
        let create_resp: Post = client.collection("posts").unwrap().create(new_post).call().await?;
        // update post
        let updated_post = CreatePost {
            name: "not_wood".to_string(),
            content: "no".to_string()
        };
        let updated_post: Post = client.collection("posts").unwrap().update("s42mpy041qkmnzp", updated_post).call().await?;
        // delete post
        client.collection("posts").unwrap().delete("yqh6x1oz9sesnc2").call().await?;
        Ok(())
}
Commit count: 0

cargo fmt