surrealdb-sql 1.1.0

Full type definitions for the SurrealQL query language
Documentation
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
use crate::err::Error;

impl<'a> Document<'a> {
	pub async fn changefeeds(
		&self,
		_ctx: &Context<'_>,
		opt: &Options,
		txn: &Transaction,
		_stm: &Statement<'_>,
	) -> Result<(), Error> {
		// Check if changed
		if !self.changed() {
			return Ok(());
		}
		//
		let tb = self.tb(opt, txn).await?;
		// Clone transaction
		let run = txn.clone();
		// Claim transaction
		let mut run = run.lock().await;
		// Get the database and the table for the record
		let db = run.add_and_cache_db(opt.ns(), opt.db(), opt.strict).await?;
		// Check if changefeeds are enabled
		if db.changefeed.is_some() || tb.changefeed.is_some() {
			// Get the arguments
			let tb = tb.name.as_str();
			let id = self.id.as_ref().unwrap();
			// Create the changefeed entry
			run.record_change(opt.ns(), opt.db(), tb, id, self.current.doc.clone());
		}
		// Carry on
		Ok(())
	}
}