From 7596060fc310c485246e1a6898003189f936d2b3 Mon Sep 17 00:00:00 2001 From: Joshua Oladele Date: Wed, 3 Jan 2024 06:29:25 +0100 Subject: [PATCH] Imrpove raw query client visibility Since it is an internal concern, we can get rid of the `get_` proxy. --- chaindexing/src/contract_states.rs | 8 ++++---- chaindexing/src/contract_states/state_versions.rs | 1 - chaindexing/src/contract_states/state_views.rs | 1 - chaindexing/src/event_handlers.rs | 6 +----- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/chaindexing/src/contract_states.rs b/chaindexing/src/contract_states.rs index 55c32a3..187b0ed 100644 --- a/chaindexing/src/contract_states.rs +++ b/chaindexing/src/contract_states.rs @@ -77,7 +77,7 @@ pub trait ContractState: async fn create<'a, S: Send + Sync + Clone>(&self, context: &EventHandlerContext) { let event = &context.event; - let client = context.get_raw_query_client(); + let client = context.raw_query_client; let state_view = self.to_view(); let table_name = Self::table_name(); @@ -93,7 +93,7 @@ pub trait ContractState: context: &EventHandlerContext, ) { let event = &context.event; - let client = context.get_raw_query_client(); + let client = context.raw_query_client; let table_name = Self::table_name(); let state_view = self.to_complete_view(table_name, client).await; @@ -105,7 +105,7 @@ pub trait ContractState: async fn delete<'a, S: Send + Sync + Clone>(&self, context: &EventHandlerContext) { let event = &context.event; - let client = context.get_raw_query_client(); + let client = context.raw_query_client; let table_name = Self::table_name(); let state_view = self.to_complete_view(table_name, client).await; @@ -128,7 +128,7 @@ pub trait ContractState: filters: HashMap, context: &EventHandlerContext, ) -> Vec { - let client = context.get_raw_query_client(); + let client = context.raw_query_client; let raw_query = format!( "SELECT * FROM {table_name} WHERE {filters}", diff --git a/chaindexing/src/contract_states/state_versions.rs b/chaindexing/src/contract_states/state_versions.rs index 765310e..ecaddb3 100644 --- a/chaindexing/src/contract_states/state_versions.rs +++ b/chaindexing/src/contract_states/state_versions.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -pub use crate::event_handlers::EventHandlerContext; use crate::Event; use crate::{ ChaindexingRepo, ChaindexingRepoRawQueryTxnClient, ExecutesWithRawQuery, LoadsDataWithRawQuery, diff --git a/chaindexing/src/contract_states/state_views.rs b/chaindexing/src/contract_states/state_views.rs index eaa8739..dc9db34 100644 --- a/chaindexing/src/contract_states/state_views.rs +++ b/chaindexing/src/contract_states/state_views.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -pub use crate::event_handlers::EventHandlerContext; use crate::{ ChaindexingRepo, ChaindexingRepoRawQueryTxnClient, ExecutesWithRawQuery, LoadsDataWithRawQuery, }; diff --git a/chaindexing/src/event_handlers.rs b/chaindexing/src/event_handlers.rs index 582308f..28a8ed3 100644 --- a/chaindexing/src/event_handlers.rs +++ b/chaindexing/src/event_handlers.rs @@ -12,7 +12,7 @@ use crate::{ChaindexingRepoRawQueryTxnClient, HasRawQueryClient}; #[derive(Clone)] pub struct EventHandlerContext<'a, SharedState: Sync + Send + Clone> { pub event: Event, - raw_query_client: &'a ChaindexingRepoRawQueryTxnClient<'a>, + pub(super) raw_query_client: &'a ChaindexingRepoRawQueryTxnClient<'a>, shared_state: Option>>, } @@ -34,10 +34,6 @@ impl<'a, SharedState: Sync + Send + Clone> EventHandlerContext<'a, SharedState> let shared_state = shared_state.lock().await; shared_state.clone() } - - pub(super) fn get_raw_query_client(&self) -> &'a ChaindexingRepoRawQueryTxnClient<'a> { - self.raw_query_client - } } #[async_trait::async_trait]