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; impl<'a> Document<'a> { pub async fn insert( &mut self, ctx: &Context<'_>, opt: &Options, stm: &Statement<'_>, ) -> Result { // Check current record match self.current.is_some() { // Run INSERT clause false => { // Check if allowed self.allow(ctx, opt, stm).await?; // Merge record data self.merge(ctx, opt, stm).await?; // Merge fields data self.field(ctx, opt, stm).await?; // Reset fields data self.reset(ctx, opt, stm).await?; // Clean fields data self.clean(ctx, opt, stm).await?; // Check if allowed self.allow(ctx, opt, stm).await?; // Store index data self.index(ctx, opt, stm).await?; // Store record data self.store(ctx, opt, stm).await?; // Run table queries self.table(ctx, opt, stm).await?; // Run lives queries self.lives(ctx, opt, stm).await?; // Run event queries self.event(ctx, opt, stm).await?; // Yield document self.pluck(ctx, opt, stm).await } // Run UPDATE clause true => { // Check if allowed self.allow(ctx, opt, stm).await?; // Alter record data self.alter(ctx, opt, stm).await?; // Merge fields data self.field(ctx, opt, stm).await?; // Reset fields data self.reset(ctx, opt, stm).await?; // Clean fields data self.clean(ctx, opt, stm).await?; // Check if allowed self.allow(ctx, opt, stm).await?; // Store index data self.index(ctx, opt, stm).await?; // Store record data self.store(ctx, opt, stm).await?; // Run table queries self.table(ctx, opt, stm).await?; // Run lives queries self.lives(ctx, opt, stm).await?; // Run event queries self.event(ctx, opt, stm).await?; // Yield document self.pluck(ctx, opt, stm).await } } } }