use super::super::inner::action;
use crate::handles::{DbRead, DbWrite};
use crate::kind::Dht;
use crate::models::dht::AgentActivityItem;
use holo_hash::{ActionHash, AgentPubKey, AnyLinkableHash, EntryHash};
use holochain_integrity_types::action::RecordValidity;
use holochain_zome_types::action::SignedActionHashed;
impl DbWrite<Dht> {
pub async fn insert_action(
&self,
action: &SignedActionHashed,
record_validity: Option<RecordValidity>,
) -> sqlx::Result<()> {
action::insert_action(self.pool(), action, record_validity).await
}
}
impl DbRead<Dht> {
pub async fn get_action(&self, hash: ActionHash) -> sqlx::Result<Option<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_action(&mut *conn, hash).await
}
pub async fn get_actions_by_author(
&self,
author: AgentPubKey,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_actions_by_author(&mut *conn, author).await
}
pub async fn count_author_actions_capped(
&self,
author: &AgentPubKey,
cap: i64,
) -> sqlx::Result<i64> {
let mut conn = self.timed_conn().await?;
action::count_author_actions_capped(&mut *conn, author, cap).await
}
pub async fn chain_head_for_author(
&self,
author: &AgentPubKey,
) -> sqlx::Result<Option<(ActionHash, u32, holochain_timestamp::Timestamp)>> {
let mut conn = self.timed_conn().await?;
action::chain_head_for_author(&mut *conn, author).await
}
pub async fn get_agent_activity(
&self,
author: AgentPubKey,
include_entries: bool,
) -> sqlx::Result<Vec<AgentActivityItem>> {
let mut conn = self.timed_conn().await?;
action::get_agent_activity(&mut *conn, &author, include_entries).await
}
pub async fn get_filtered_agent_activity(
&self,
author: AgentPubKey,
chain_top_seq: u32,
until_seq: Option<u32>,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_filtered_agent_activity(&mut *conn, &author, chain_top_seq, until_seq).await
}
pub async fn get_action_seq_and_timestamp(
&self,
author: AgentPubKey,
action_hash: ActionHash,
) -> sqlx::Result<Option<(u32, holochain_timestamp::Timestamp)>> {
let mut conn = self.timed_conn().await?;
action::get_action_seq_and_timestamp(&mut *conn, &author, &action_hash).await
}
pub async fn get_actions_by_prev_hash(
&self,
prev_hash: &ActionHash,
exclude_hash: &ActionHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_actions_by_prev_hash(&mut *conn, prev_hash, exclude_hash).await
}
pub async fn get_create_actions_for_entry(
&self,
entry_hash: &EntryHash,
author: Option<&AgentPubKey>,
validation_status: RecordValidity,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_create_actions_for_entry(&mut *conn, entry_hash, author, validation_status)
.await
}
pub async fn get_delete_actions_for_entry(
&self,
entry_hash: &EntryHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_delete_actions_for_entry(&mut *conn, entry_hash).await
}
pub async fn get_update_actions_for_entry(
&self,
entry_hash: &EntryHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_update_actions_for_entry(&mut *conn, entry_hash).await
}
pub async fn get_live_entry_creates(
&self,
entry_hash: &EntryHash,
author: Option<&AgentPubKey>,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_live_entry_creates(&mut *conn, entry_hash, author).await
}
pub async fn get_delete_actions_for_record(
&self,
record_action_hash: &ActionHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_delete_actions_for_record(&mut *conn, record_action_hash).await
}
pub async fn get_update_actions_for_record(
&self,
record_action_hash: &ActionHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_update_actions_for_record(&mut *conn, record_action_hash).await
}
pub async fn get_live_link_actions(
&self,
base: &AnyLinkableHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_live_link_actions(&mut *conn, base).await
}
pub async fn get_link_create_actions(
&self,
base: &AnyLinkableHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_link_create_actions(&mut *conn, base).await
}
pub async fn get_delete_link_actions(
&self,
create_link_hash: &ActionHash,
) -> sqlx::Result<Vec<SignedActionHashed>> {
let mut conn = self.timed_conn().await?;
action::get_delete_link_actions(&mut *conn, create_link_hash).await
}
pub async fn get_authority_link_creates(
&self,
base: &AnyLinkableHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_link_creates(&mut *conn, base).await
}
pub async fn get_authority_delete_links(
&self,
base: &AnyLinkableHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_delete_links(&mut *conn, base).await
}
pub async fn get_authority_store_record(
&self,
action_hash: &ActionHash,
) -> sqlx::Result<Option<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_store_record(&mut *conn, action_hash).await
}
pub async fn get_authority_deletes_for_record(
&self,
record_action_hash: &ActionHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_deletes_for_record(&mut *conn, record_action_hash).await
}
pub async fn get_authority_updates_for_record(
&self,
record_action_hash: &ActionHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_updates_for_record(&mut *conn, record_action_hash).await
}
pub async fn get_authority_entry_creates(
&self,
entry_hash: &EntryHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_entry_creates(&mut *conn, entry_hash).await
}
pub async fn get_authority_deletes_for_entry(
&self,
entry_hash: &EntryHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_deletes_for_entry(&mut *conn, entry_hash).await
}
pub async fn get_authority_updates_for_entry(
&self,
entry_hash: &EntryHash,
) -> sqlx::Result<Vec<(SignedActionHashed, RecordValidity)>> {
let mut conn = self.timed_conn().await?;
action::get_authority_updates_for_entry(&mut *conn, entry_hash).await
}
}