baserow_rs::api::table_operations

Trait BaserowTableOperations

Source
pub trait BaserowTableOperations {
    // Required methods
    fn auto_map<'async_trait>(
        self,
    ) -> Pin<Box<dyn Future<Output = Result<BaserowTable, Box<dyn Error>>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn query(self) -> RowRequestBuilder;
    fn rows(self) -> RowRequestBuilder;
    fn get<'life0, 'async_trait, T>(
        &'life0 self,
        baserow: Baserow,
        request: RowRequest,
    ) -> Pin<Box<dyn Future<Output = Result<TypedRowsResponse<T>, Box<dyn Error>>> + Send + 'async_trait>>
       where T: DeserializeOwned + 'static + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn create_one<'async_trait>(
        self,
        data: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, Box<dyn Error>>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn get_one<'async_trait, T>(
        self,
        id: u64,
    ) -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error>>> + Send + 'async_trait>>
       where T: DeserializeOwned + 'static + 'async_trait,
             Self: 'async_trait;
    fn update<'async_trait>(
        self,
        id: u64,
        data: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, Box<dyn Error>>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn delete<'async_trait>(
        self,
        id: u64,
    ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Trait defining the public operations available on a Baserow table

This trait provides the core CRUD operations for working with Baserow tables. All operations are async and return Results to handle potential errors.

§Example

use baserow_rs::{ConfigBuilder, Baserow, BaserowTableOperations, api::client::BaserowClient};
use std::collections::HashMap;
use serde_json::Value;

#[tokio::main]
async fn main() {
    let config = ConfigBuilder::new()
        .base_url("https://api.baserow.io")
        .api_key("your-api-key")
        .build();

    let baserow = Baserow::with_configuration(config);
    let table = baserow.table_by_id(1234);

    // Create a new record
    let mut data = HashMap::new();
    data.insert("Name".to_string(), Value::String("Test".to_string()));
    let result = table.create_one(data).await.unwrap();
}

Required Methods§

Source

fn auto_map<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<BaserowTable, Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,

Automatically maps the table fields to their corresponding types

This method fetches the table schema and sets up field mappings for type conversion. Call this before performing operations if you need type-safe field access.

Source

fn query(self) -> RowRequestBuilder

Creates a new query builder for constructing complex table queries

This is the preferred method for building queries with filters, sorting, and pagination options. The builder provides a fluent interface for constructing queries.

§Example
use baserow_rs::{ConfigBuilder, Baserow, BaserowTableOperations, OrderDirection, filter::Filter};
use baserow_rs::api::client::BaserowClient;
use std::collections::HashMap;
use serde_json::Value;

#[tokio::main]
async fn main() {
    let baserow = Baserow::with_configuration(ConfigBuilder::new().build());
    let table = baserow.table_by_id(1234);

    let results = table.query()
        .filter_by("Status", Filter::Equal, "Active")
        .order_by("Created", OrderDirection::Desc)
        .get::<HashMap<String, Value>>()
        .await
        .unwrap();
}
Source

fn rows(self) -> RowRequestBuilder

👎Deprecated since 0.1.0: Use the query() method instead
Source

fn get<'life0, 'async_trait, T>( &'life0 self, baserow: Baserow, request: RowRequest, ) -> Pin<Box<dyn Future<Output = Result<TypedRowsResponse<T>, Box<dyn Error>>> + Send + 'async_trait>>
where T: DeserializeOwned + 'static + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Execute a row request and return typed results

§Type Parameters
  • T - The type to deserialize the results into
§Arguments
  • request - The query parameters encapsulated in a RowRequest
§Returns

A TypedRowsResponse containing the query results and pagination information

Source

fn create_one<'async_trait>( self, data: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,

Creates a single record in the table

§Arguments
  • data - A map of field names to values representing the record to create
§Returns

The created record including any auto-generated fields (like ID)

Source

fn get_one<'async_trait, T>( self, id: u64, ) -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error>>> + Send + 'async_trait>>
where T: DeserializeOwned + 'static + 'async_trait, Self: 'async_trait,

Retrieves a single record from the table by ID

§Type Parameters
  • T - The type to deserialize into. Defaults to HashMap<String, Value>. When using a custom type, the table must be mapped using auto_map() first.
§Arguments
  • id - The unique identifier of the record to retrieve
§Returns

The requested record if found, either as a HashMap or deserialized into type T

§Example
use baserow_rs::{ConfigBuilder, Baserow, BaserowTableOperations, api::client::BaserowClient};
use serde::Deserialize;
use std::collections::HashMap;
use serde_json::Value;

#[derive(Deserialize)]
struct User {
    name: String,
    email: String,
}

#[tokio::main]
async fn main() {
    let config = ConfigBuilder::new()
        .base_url("https://api.baserow.io")
        .api_key("your-api-key")
        .build();

    let baserow = Baserow::with_configuration(config);
    let table = baserow.table_by_id(1234);

    // Get as HashMap (default)
    let row: HashMap<String, Value> = table.clone().get_one(1).await.unwrap();

    // Get as typed struct
    let user: User = table.auto_map()
        .await
        .unwrap()
        .get_one(1)
        .await
        .unwrap();
}
Source

fn update<'async_trait>( self, id: u64, data: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,

Updates a single record in the table

§Arguments
  • id - The unique identifier of the record to update
  • data - A map of field names to new values
§Returns

The updated record

Source

fn delete<'async_trait>( self, id: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,

Deletes a single record from the table

§Arguments
  • id - The unique identifier of the record to delete

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§