use crate::client::Client;
use crate::error::Result;
use crate::models::{
AddCollectionRequest, GenericResponse, InsertRecordRequest, InsertRecordResponse,
ListCollectionsResponse,
};
use reqwest::Response;
impl Client {
pub async fn list_collections(&self) -> Result<ListCollectionsResponse> {
self.do_request::<ListCollectionsResponse, ()>(
reqwest::Method::GET,
"/api/collections/v1/",
None,
None,
)
.await
}
pub async fn add_collection(&self, req: &AddCollectionRequest) -> Result<GenericResponse> {
self.do_request(
reqwest::Method::POST,
"/api/collections/v1/",
Some(req),
None,
)
.await
}
pub async fn delete_record(
&self,
collection_name: &str,
id: &str,
) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/{}", collection_name, id);
self.do_request::<GenericResponse, ()>(reqwest::Method::DELETE, &path, None, None)
.await
}
pub async fn expiry_cleanup(&self, collection_name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/expiry-cleanup", collection_name);
self.do_request::<GenericResponse, ()>(reqwest::Method::POST, &path, None, None)
.await
}
pub async fn drop_collection(&self, name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}", name);
self.do_request::<GenericResponse, ()>(reqwest::Method::DELETE, &path, None, None)
.await
}
pub async fn flush_collection(&self, name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/flush", name);
self.do_request::<GenericResponse, ()>(reqwest::Method::POST, &path, None, None)
.await
}
pub async fn load_collection(&self, name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/load", name);
self.do_request::<GenericResponse, ()>(reqwest::Method::POST, &path, None, None)
.await
}
pub async fn unload_collection(&self, name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/unload", name);
self.do_request::<GenericResponse, ()>(reqwest::Method::POST, &path, None, None)
.await
}
pub async fn export_collection(&self, name: &str) -> Result<Response> {
let path = format!("/api/collections/v1/{}/export", name);
self.do_request_with_file_response(reqwest::Method::POST, &path, None)
.await
}
pub async fn import_collection(&self, file_path: &std::path::Path) -> Result<()> {
self.do_file_request(
reqwest::Method::POST,
"/api/collections/v1/import",
file_path,
)
.await
}
pub async fn rename_collection(
&self,
old_name: &str,
new_name: &str,
) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/rename/{}", old_name, new_name);
self.do_request::<GenericResponse, ()>(reqwest::Method::PUT, &path, None, None)
.await
}
pub async fn reindex_collection(&self, collection_name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/reindex", collection_name);
self.do_request::<GenericResponse, ()>(reqwest::Method::PUT, &path, None, None)
.await
}
pub async fn pq_train(&self, collection_name: &str) -> Result<GenericResponse> {
let path = format!("/api/collections/v1/{}/pq-train", collection_name);
self.do_request::<GenericResponse, ()>(reqwest::Method::POST, &path, None, None)
.await
}
pub async fn insert_record(&self, req: &InsertRecordRequest) -> Result<InsertRecordResponse> {
self.do_request(
reqwest::Method::POST,
"/api/collections/v1/record",
Some(req),
None,
)
.await
}
}