pub async fn list_regions(
pool: &Pool<MySql>,
limit: Option<i64>,
offset: Option<i64>,
) -> Result<Vec<Region>>
Expand description
Retrieves a paginated list of deployment regions.
This function fetches regions from the database with optional pagination support. Results are ordered by creation time with the most recently created regions first.
§Arguments
pool
- Database connection pool for executing the querylimit
- Optional maximum number of regions to return (defaults to 100 if not specified)offset
- Optional number of regions to skip (for pagination)
§Returns
Ok(Vec<Region>)
- Successfully retrieved list of regionsErr(anyhow::Error)
- Failed to fetch regions
§Dynamic Query Building
This function uses SQLx’s QueryBuilder to dynamically construct a SQL query based on whether pagination parameters are provided. This approach is more efficient than building strings manually and protects against SQL injection.
§Pagination
When both limit
and offset
are provided, standard SQL pagination is applied.
If only limit
is provided, just the first N records are returned.
If neither is provided, all regions are returned (with a safety limit of 100).