pub fn fetch_all<T: SqlQuery + FromRow + SqlParams>(
client: &mut Client,
params: &T,
) -> Result<Vec<T>, Error>
Expand description
§fetch_all
Retrieves multiple records from the database.
§Parameters
client
: Database connection clientparams
: Query parameters (must implement SqlQuery, FromRow, and SqlParams traits)
§Return Value
Result<Vec<T>, Error>
: On success, returns a vector of records; on failure, returns Error
§Struct Definition
Structs used with this function should be annotated with the following derive macros:
#[derive(Queryable, FromRow, SqlParams)] // Required macros
#[table("users")] // Table name to query
#[where_clause("active = $1")] // WHERE clause with parameter placeholders
struct GetUsers {
active: bool, // Parameter for the WHERE clause
id: i32, // Field to retrieve
name: String, // Field to retrieve
email: String, // Field to retrieve
}