Skip to main content

get_table

Function get_table 

Source
pub async fn get_table(
    db: &DB,
    table: &str,
    page: usize,
) -> Result<TableRecords, Box<dyn Error + Send + Sync>>
Expand description

Retrieves records from a specific table in the database, with pagination support.

§Arguments

  • db - A reference to the database connection.
  • table - The name of the table to retrieve records from.
  • page - The page number to retrieve (1-based index).

§Returns

  • Ok(TableRecords) - A struct containing the records, total count, current page, total pages, and size in bytes if the query is successful.
  • Err(Box<dyn Error + Send + Sync>) - An error if the query fails or if the table does not exist.

§Examples

let table_records = get_table(&db, "users", 1).await.unwrap();
println!("Total records: {}", table_records.total);
for record in table_records.records {
    println!("{:?}", record);
}