surrealcs 0.4.4

The SurrealCS client code for SurrealDB
Documentation
#![allow(clippy::module_inception)]

//! Defines the handle of a transaction to enable users create transactions and
//! send transaction operations to a transaction to a server.
use std::marker::PhantomData;
use tokio::sync::mpsc;

use surrealcs_kernel::messages::client::message::TransactionMessage;

#[derive(Debug)]
pub struct NotStarted;
#[derive(Debug)]
pub struct InProgress;
#[derive(Debug)]
pub struct Committed;
#[derive(Debug)]
pub struct RolledBack;
#[derive(Debug)]
pub struct Any;

/// The handle for a transaction.
///
/// # Notes
/// There is some danger in sending a send operation to the server before
/// sending a begin transaction message. This will kill the reader on the
/// server so I think we need to implement the typestate pattern here to
/// ensure this can never happen and also lock down the reader in the server.
///
/// # Fields
/// * `client_id`: the index for the connection router on the client.
/// * `server_id`: the index for the router on a server
/// * `receiver`: a handle to recieving messages from the connection router
/// * `sender`: a handle to send messages to the connection writer
/// * `connection_id`: the id of the connection (for logging mainly)
/// * `transaction_id`: the id of the transaction for logging so we can track the transaction
/// * `state`: the state of the transaction
#[derive(Debug)]
pub struct Transaction<State> {
	pub client_id: usize,
	pub server_id: Option<usize>,
	pub receiver: mpsc::Receiver<TransactionMessage>,
	pub sender: mpsc::Sender<TransactionMessage>,
	pub connection_id: String,
	pub transaction_id: String,
	pub state: PhantomData<State>,
}