use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Statement;
use crate::doc::Document;
use crate::err::Error;
use crate::sql::value::Value;
use reblessive::tree::Stk;
impl Document {
pub(super) async fn insert(
&mut self,
stk: &mut Stk,
ctx: &Context,
opt: &Options,
stm: &Statement<'_>,
) -> Result<Value, Error> {
match self.is_iteration_initial() {
true => match self.insert_create(stk, ctx, opt, stm).await {
Err(Error::IndexExists {
thing,
index,
value,
}) => match stm.is_retryable() {
true => match self.is_specific_record_id() {
false => Err(Error::RetryWithId(thing)),
true => Err(Error::IndexExists {
thing,
index,
value,
}),
},
false => Err(Error::IndexExists {
thing,
index,
value,
}),
},
Err(Error::RecordExists {
thing,
}) => match stm.is_retryable() {
true => Err(Error::RetryWithId(thing)),
false => match stm.is_ignore() {
false => Err(Error::RecordExists {
thing,
}),
true => Err(Error::Ignore),
},
},
Err(e) => Err(e),
Ok(v) => Ok(v),
},
false => self.insert_update(stk, ctx, opt, stm).await,
}
}
async fn insert_create(
&mut self,
stk: &mut Stk,
ctx: &Context,
opt: &Options,
stm: &Statement<'_>,
) -> Result<Value, Error> {
self.check_permissions_quick(stk, ctx, opt, stm).await?;
self.check_table_type(ctx, opt, stm).await?;
self.check_data_fields(stk, ctx, opt, stm).await?;
self.process_merge_data(stk, ctx, opt, stm).await?;
self.store_edges_data(ctx, opt, stm).await?;
self.process_table_fields(stk, ctx, opt, stm).await?;
self.cleanup_table_fields(ctx, opt, stm).await?;
self.default_record_data(ctx, opt, stm).await?;
self.check_permissions_table(stk, ctx, opt, stm).await?;
self.store_record_data(ctx, opt, stm).await?;
self.store_index_data(stk, ctx, opt, stm).await?;
self.process_table_views(stk, ctx, opt, stm).await?;
self.process_table_lives(stk, ctx, opt, stm).await?;
self.process_table_events(stk, ctx, opt, stm).await?;
self.process_changefeeds(ctx, opt, stm).await?;
self.pluck(stk, ctx, opt, stm).await
}
async fn insert_update(
&mut self,
stk: &mut Stk,
ctx: &Context,
opt: &Options,
stm: &Statement<'_>,
) -> Result<Value, Error> {
self.check_permissions_quick(stk, ctx, opt, stm).await?;
self.check_table_type(ctx, opt, stm).await?;
self.check_data_fields(stk, ctx, opt, stm).await?;
self.check_permissions_table(stk, ctx, opt, stm).await?;
self.process_record_data(stk, ctx, opt, stm).await?;
self.process_table_fields(stk, ctx, opt, stm).await?;
self.cleanup_table_fields(ctx, opt, stm).await?;
self.default_record_data(ctx, opt, stm).await?;
self.check_permissions_table(stk, ctx, opt, stm).await?;
self.store_record_data(ctx, opt, stm).await?;
self.store_index_data(stk, ctx, opt, stm).await?;
self.process_table_views(stk, ctx, opt, stm).await?;
self.process_table_lives(stk, ctx, opt, stm).await?;
self.process_table_events(stk, ctx, opt, stm).await?;
self.process_changefeeds(ctx, opt, stm).await?;
self.pluck(stk, ctx, opt, stm).await
}
}