use crate::{Client, Error, execute_wrapper};
use typesense_codegen::{
apis::collections_api::{self, GetCollectionsParams},
models::{self, GetCollectionsParameters},
};
pub struct Collections<'c> {
pub(super) client: &'c Client,
}
impl<'c> Collections<'c> {
#[inline]
pub(super) fn new(client: &'c Client) -> Self {
Self { client }
}
pub async fn create(
&self,
schema: models::CollectionSchema<'_>,
) -> Result<models::CollectionResponse, Error<collections_api::CreateCollectionError>> {
let params = collections_api::CreateCollectionParams {
collection_schema: schema,
};
execute_wrapper!(self, collections_api::create_collection, params)
}
pub async fn retrieve(
&self,
params: GetCollectionsParameters<'_>,
) -> Result<Vec<models::CollectionResponse>, Error<collections_api::GetCollectionsError>> {
let params = GetCollectionsParams {
exclude_fields: params.exclude_fields,
limit: params.limit,
offset: params.offset,
};
execute_wrapper!(self, collections_api::get_collections, params)
}
}