holochain_data 0.7.0-rc.1

Database abstraction layer for Holochain using sqlx
Documentation
//! `DbRead<Dht>` / `DbWrite<Dht>` API for the `LimboChainOp` table.

use super::super::inner::limbo_chain_op::{self, InsertLimboChainOp};
use crate::handles::{DbRead, DbWrite};
use crate::kind::Dht;
use crate::models::dht::LimboChainOpRow;
use holo_hash::DhtOpHash;
use holochain_integrity_types::action::OpValidity;
use holochain_timestamp::Timestamp;

impl DbWrite<Dht> {
    pub async fn insert_limbo_chain_op(&self, op: InsertLimboChainOp<'_>) -> sqlx::Result<()> {
        limbo_chain_op::insert_limbo_chain_op(self.pool(), op).await
    }

    pub async fn delete_limbo_chain_op(&self, hash: DhtOpHash) -> sqlx::Result<()> {
        limbo_chain_op::delete_limbo_chain_op(self.pool(), hash).await
    }

    /// Set the system-validation status for the given op. Returns the number of rows updated.
    pub async fn set_limbo_chain_op_sys_validation_status(
        &self,
        op_hash: &DhtOpHash,
        status: Option<i64>,
    ) -> sqlx::Result<u64> {
        limbo_chain_op::set_sys_validation_status(self.pool(), op_hash, status).await
    }

    /// Set the app-validation status for the given op. Returns the number of rows updated.
    pub async fn set_limbo_chain_op_app_validation_status(
        &self,
        op_hash: &DhtOpHash,
        status: Option<i64>,
    ) -> sqlx::Result<u64> {
        limbo_chain_op::set_app_validation_status(self.pool(), op_hash, status).await
    }

    /// Atomically promote a `LimboChainOp` row to the `ChainOp` table.
    ///
    /// Begins a transaction, delegates to the inner promotion helper, and
    /// commits on success.  Returns `true` if the limbo row existed and was
    /// promoted, `false` if it did not exist.
    pub async fn promote_limbo_chain_op(
        &self,
        op_hash: &DhtOpHash,
        validation_status: OpValidity,
        when_integrated: Timestamp,
    ) -> sqlx::Result<bool> {
        let mut tx = self.begin().await?;
        let result = limbo_chain_op::promote_to_chain_op(
            tx.conn_mut(),
            op_hash,
            validation_status,
            when_integrated,
        )
        .await?;
        tx.commit().await?;
        Ok(result)
    }
}

impl DbRead<Dht> {
    pub async fn get_limbo_chain_op(
        &self,
        hash: DhtOpHash,
    ) -> sqlx::Result<Option<LimboChainOpRow>> {
        let mut conn = self.timed_conn().await?;
        limbo_chain_op::get_limbo_chain_op(&mut *conn, hash).await
    }

    pub async fn limbo_chain_ops_pending_sys_validation(
        &self,
        limit: u32,
    ) -> sqlx::Result<Vec<LimboChainOpRow>> {
        let mut conn = self.timed_conn().await?;
        limbo_chain_op::limbo_chain_ops_pending_sys_validation(&mut *conn, limit).await
    }

    pub async fn limbo_chain_ops_pending_app_validation(
        &self,
        limit: u32,
    ) -> sqlx::Result<Vec<LimboChainOpRow>> {
        let mut conn = self.timed_conn().await?;
        limbo_chain_op::limbo_chain_ops_pending_app_validation(&mut *conn, limit).await
    }

    pub async fn limbo_chain_ops_ready_for_integration(
        &self,
        limit: u32,
    ) -> sqlx::Result<Vec<LimboChainOpRow>> {
        let mut conn = self.timed_conn().await?;
        limbo_chain_op::limbo_chain_ops_ready_for_integration(&mut *conn, limit).await
    }

    /// Fetch limbo chain ops pending sys-validation joined with their `Action`
    /// and optional `Entry` in a single round-trip.
    pub async fn limbo_chain_ops_pending_sys_validation_with_action(
        &self,
        limit: u32,
    ) -> sqlx::Result<Vec<limbo_chain_op::LimboChainOpJoinedRow>> {
        let mut conn = self.timed_conn().await?;
        limbo_chain_op::limbo_chain_ops_pending_sys_validation_with_action(&mut *conn, limit).await
    }

    /// Fetch limbo chain ops pending app-validation joined with their `Action`
    /// and optional `Entry` in a single round-trip.
    pub async fn limbo_chain_ops_pending_app_validation_with_action(
        &self,
        limit: u32,
    ) -> sqlx::Result<Vec<limbo_chain_op::LimboChainOpJoinedRow>> {
        let mut conn = self.timed_conn().await?;
        limbo_chain_op::limbo_chain_ops_pending_app_validation_with_action(&mut *conn, limit).await
    }
}