use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug)]
pub struct MultiObjects {
pub objects: Vec<Object>,
}
impl MultiObjects {
pub fn new(objects: Vec<Object>) -> MultiObjects {
MultiObjects { objects }
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Object {
pub class: String,
pub properties: serde_json::Value,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vector: Option<Vec<f64>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub tenant: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub creation_time_unix: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub last_update_time_unix: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vector_weights: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub additional: Option<serde_json::Value>,
}
impl Object {
pub fn builder(class: &str, properties: serde_json::Value) -> ObjectBuilder {
ObjectBuilder::new(class, properties)
}
}
pub struct ObjectBuilder {
pub class: String,
pub properties: serde_json::Value,
pub id: Option<Uuid>,
pub vector: Option<Vec<f64>>,
pub tenant: Option<String>,
pub creation_time_unix: Option<u64>,
pub last_update_time_unix: Option<u64>,
pub vector_weights: Option<u64>,
}
impl ObjectBuilder {
pub fn new(class: &str, properties: serde_json::Value) -> ObjectBuilder {
ObjectBuilder {
class: class.into(),
properties,
id: None,
vector: None,
tenant: None,
creation_time_unix: None,
last_update_time_unix: None,
vector_weights: None,
}
}
pub fn with_id(mut self, id: Uuid) -> ObjectBuilder {
self.id = Some(id);
self
}
pub fn with_vector(mut self, vector: Vec<f64>) -> ObjectBuilder {
self.vector = Some(vector);
self
}
pub fn with_tenant(mut self, tenant: &str) -> ObjectBuilder {
self.tenant = Some(tenant.into());
self
}
pub fn with_vector_weights(mut self, vector_weights: u64) -> ObjectBuilder {
self.vector_weights = Some(vector_weights);
self
}
pub fn build(self) -> Object {
Object {
class: self.class,
properties: self.properties,
id: self.id,
vector: self.vector,
tenant: self.tenant,
creation_time_unix: self.creation_time_unix,
last_update_time_unix: self.last_update_time_unix,
vector_weights: self.vector_weights,
additional: None
}
}
}
pub enum OrderBy {
ASC,
DESC,
}
impl OrderBy {
pub fn value(&self) -> &str {
match self {
OrderBy::ASC => "asc",
OrderBy::DESC => "desc",
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub enum ConsistencyLevel {
ONE,
QUORUM,
ALL,
}
impl ConsistencyLevel {
pub fn value(&self) -> &str {
match self {
ConsistencyLevel::ONE => "ONE",
ConsistencyLevel::QUORUM => "QUORUM",
ConsistencyLevel::ALL => "ALL",
}
}
}
#[derive(Debug, Default)]
pub struct ObjectListParameters {
pub class_name: Option<String>,
pub limit: Option<u64>,
pub offset: Option<u64>,
pub after: Option<String>,
pub include: Option<String>,
pub sort: Option<Vec<String>>,
pub order: Option<Vec<String>>,
}
impl ObjectListParameters {
pub fn new() -> ObjectListParameters {
ObjectListParameters::default()
}
pub fn builder() -> ObjectListParametersBuilder {
ObjectListParametersBuilder::default()
}
}
#[derive(Debug, Default)]
pub struct ObjectListParametersBuilder {
pub class_name: Option<String>,
pub limit: Option<u64>,
pub offset: Option<u64>,
pub after: Option<String>,
pub include: Option<String>,
pub sort: Option<Vec<String>>,
pub order: Option<Vec<String>>,
}
impl ObjectListParametersBuilder {
pub fn new() -> ObjectListParametersBuilder {
ObjectListParametersBuilder::default()
}
pub fn with_class_name(mut self, class_name: &str) -> ObjectListParametersBuilder {
self.class_name = Some(class_name.into());
self
}
pub fn with_limit(mut self, limit: u64) -> ObjectListParametersBuilder {
self.limit = Some(limit);
self
}
pub fn with_offset(mut self, offset: u64) -> ObjectListParametersBuilder {
self.offset = Some(offset);
self
}
pub fn with_after(mut self, after: &str) -> ObjectListParametersBuilder {
self.after = Some(after.into());
self
}
pub fn with_include(mut self, include: &str) -> ObjectListParametersBuilder {
self.include = Some(include.into());
self
}
pub fn with_sort(mut self, sort: Vec<&str>) -> ObjectListParametersBuilder {
let sort = sort.iter().map(|field| field.to_string()).collect();
self.sort = Some(sort);
self
}
pub fn with_order(mut self, order: Vec<&str>) -> ObjectListParametersBuilder {
let order = order.iter().map(|field| field.to_string()).collect();
self.order = Some(order);
self
}
pub fn build(self) -> ObjectListParameters {
ObjectListParameters {
class_name: self.class_name,
limit: self.limit,
offset: self.offset,
after: self.after,
include: self.include,
sort: self.sort,
order: self.order,
}
}
}
pub struct References(pub Vec<Reference>);
impl References {
pub fn new(references: Vec<Reference>) -> References {
References(references)
}
}
pub struct Reference {
pub from_class_name: String,
pub from_uuid: Uuid,
pub from_property_name: String,
pub to_class_name: String,
pub to_uuid: Uuid,
pub consistency_level: Option<ConsistencyLevel>,
pub tenant_name: Option<String>,
}
impl Reference {
pub fn new(
from_class_name: &str,
from_uuid: &Uuid,
from_property_name: &str,
to_class_name: &str,
to_uuid: &Uuid,
) -> Reference {
Reference {
from_class_name: from_class_name.into(),
from_uuid: from_uuid.clone(),
from_property_name: from_property_name.into(),
to_class_name: to_class_name.into(),
to_uuid: to_uuid.clone(),
consistency_level: None,
tenant_name: None,
}
}
pub fn builder(
from_class_name: &str,
from_uuid: &Uuid,
from_property_name: &str,
to_class_name: &str,
to_uuid: &Uuid,
) -> ReferenceBuilder {
ReferenceBuilder::new(
from_class_name,
from_uuid,
from_property_name,
to_class_name,
to_uuid,
)
}
}
pub struct ReferenceBuilder {
pub from_class_name: String,
pub from_uuid: Uuid,
pub from_property_name: String,
pub to_class_name: String,
pub to_uuid: Uuid,
pub consistency_level: Option<ConsistencyLevel>,
pub tenant_name: Option<String>,
}
impl ReferenceBuilder {
pub fn new(
from_class_name: &str,
from_uuid: &Uuid,
from_property_name: &str,
to_class_name: &str,
to_uuid: &Uuid,
) -> ReferenceBuilder {
ReferenceBuilder {
from_class_name: from_class_name.into(),
from_uuid: from_uuid.clone(),
from_property_name: from_property_name.into(),
to_class_name: to_class_name.into(),
to_uuid: to_uuid.clone(),
consistency_level: None,
tenant_name: None,
}
}
pub fn with_consistency_level(
mut self,
consistency_level: ConsistencyLevel,
) -> ReferenceBuilder {
self.consistency_level = Some(consistency_level);
self
}
pub fn with_tenant_name(mut self, tenant_name: &str) -> ReferenceBuilder {
self.tenant_name = Some(tenant_name.into());
self
}
pub fn build(self) -> Reference {
Reference {
from_class_name: self.from_class_name,
from_uuid: self.from_uuid,
from_property_name: self.from_property_name,
to_class_name: self.to_class_name,
to_uuid: self.to_uuid,
consistency_level: self.consistency_level,
tenant_name: self.tenant_name,
}
}
}