use std::fmt::{Debug, Display, Formatter};
use std::borrow::Borrow;
use key_path::path;
use teo_runtime::connection::transaction;
use teo_runtime::model;
use crate::prelude::{Value, Result};
pub struct DataSetRecord {
pub(super) inner: model::Object,
}
impl PartialEq for DataSetRecord {
fn eq(&self, other: &Self) -> bool {
self.inner.eq(&other.inner)
}
}
impl DataSetRecord {
pub async fn find_many(query: impl Borrow<Value>, ctx: transaction::Ctx) -> Result<Vec<DataSetRecord>> {
let model = ctx.namespace().model_at_path(&vec!["std", "DataSetRecord"]).unwrap();
Ok(ctx.find_many(model, query.borrow(), None, path![]).await?)
}
pub async fn find_unique(query: impl Borrow<Value>, ctx: transaction::Ctx) -> Result<Option<DataSetRecord>> {
let model = ctx.namespace().model_at_path(&vec!["std", "DataSetRecord"]).unwrap();
Ok(ctx.find_unique(model, query.borrow(), None, path![]).await?)
}
pub async fn find_first(query: impl Borrow<Value>, ctx: transaction::Ctx) -> Result<Option<DataSetRecord>> {
let model = ctx.namespace().model_at_path(&vec!["std", "DataSetRecord"]).unwrap();
Ok(ctx.find_first(model, query.borrow(), None, path![]).await?)
}
pub async fn new(values: impl Borrow<Value>, ctx: transaction::Ctx) -> Result<Self> {
let model = ctx.namespace().model_at_path(&vec!["std", "DataSetRecord"]).unwrap();
Ok(ctx.create_object(model, values.borrow(), None).await?.into())
}
pub fn is_new(&self) -> bool {
self.inner.is_new()
}
pub fn is_modified(&self) -> bool {
self.inner.is_modified()
}
pub async fn set(&self, values: impl AsRef<Value>) -> Result<()> {
self.inner.set_teon(values.as_ref()).await
}
pub async fn update(&self, values: impl AsRef<Value>) -> Result<()> {
self.inner.update_teon(values.as_ref()).await
}
pub async fn save(&self) -> Result<()> {
self.inner.save().await
}
pub async fn delete(&self) -> Result<()> {
self.inner.delete().await
}
pub fn id(&self) -> String {
self.inner.get("id").unwrap()
}
pub fn set_id(&self, new_value: impl Into<String>) {
self.inner.set("id", new_value.into()).unwrap();
}
pub fn dataset(&self) -> String {
self.inner.get("dataSet").unwrap()
}
pub fn set_dataset(&self, new_value: impl Into<String>) {
self.inner.set("dataSet", new_value.into()).unwrap();
}
pub fn group(&self) -> Vec<String> {
let group_string: String = self.inner.get("group").unwrap();
group_string.split(".").map(|s| s.to_string()).collect()
}
pub fn set_group(&self, new_value: Vec<String>) {
let new_value_string = new_value.join(".");
self.inner.set("group", new_value_string).unwrap();
}
pub fn name(&self) -> String {
self.inner.get("name").unwrap()
}
pub fn set_name(&self, new_value: impl Into<String>) {
self.inner.set("name", new_value.into()).unwrap();
}
pub fn record(&self) -> String {
self.inner.get("record").unwrap()
}
pub fn set_record(&self, new_value: impl Into<String>) {
self.inner.set("record", new_value.into()).unwrap();
}
}
impl Into<model::Object> for DataSetRecord {
fn into(self) -> model::Object {
self.inner.clone()
}
}
impl From<model::Object> for DataSetRecord {
fn from(value: model::Object) -> Self {
Self { inner: value }
}
}
impl Debug for DataSetRecord {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self.inner, f)
}
}
impl Display for DataSetRecord {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.inner, f)
}
}