pub struct ConnectionPool(/* private fields */);
Expand description
Access to the node’s DB connection pool and DB-access-related methods.
The handle is safe to clone and share between threads.
Implementations§
source§impl ConnectionPool
impl ConnectionPool
sourcepub fn new(conf: &Config) -> Result<Self>
pub fn new(conf: &Config) -> Result<Self>
Create the connection pool from the given configuration.
sourcepub async fn acquire(&self) -> Result<ConnectionHandle, AcquireError>
pub async fn acquire(&self) -> Result<ConnectionHandle, AcquireError>
Acquire a temporary database ConnectionHandle
from the inner pool.
In the case that all connections are busy, waits for the first available connection.
sourcepub fn try_acquire(&self) -> Result<ConnectionHandle, TryAcquireError>
pub fn try_acquire(&self) -> Result<ConnectionHandle, TryAcquireError>
Attempt to synchronously acquire a temporary database ConnectionHandle
from the inner pool.
Returns Err
in the case that all database connections are busy or if
the node has been closed.
sourcepub fn close(&self) -> Result<(), ConnectionCloseErrors>
pub fn close(&self) -> Result<(), ConnectionCloseErrors>
Close a connection pool, returning a ConnectionCloseErrors
in the case of any errors.
source§impl ConnectionPool
impl ConnectionPool
Short-hand methods for async DB access.
sourcepub async fn acquire_then<F, T, E>(
&self,
f: F,
) -> Result<T, AcquireThenError<E>>
pub async fn acquire_then<F, T, E>( &self, f: F, ) -> Result<T, AcquireThenError<E>>
Asynchronous access to the node’s DB via the given function.
Requests and awaits a connection from the connection pool, then spawns a blocking task for the given function providing access to the connection handle.
sourcepub async fn create_tables(&self) -> Result<(), AcquireThenRusqliteError>
pub async fn create_tables(&self) -> Result<(), AcquireThenRusqliteError>
Create all database tables.
sourcepub async fn insert_block(
&self,
block: Arc<Block>,
) -> Result<ContentAddress, AcquireThenRusqliteError>
pub async fn insert_block( &self, block: Arc<Block>, ) -> Result<ContentAddress, AcquireThenRusqliteError>
Insert the given block into the block
table and for each of its
solutions, add a row into the solution
and block_solution
tables.
sourcepub async fn finalize_block(
&self,
block_ca: ContentAddress,
) -> Result<(), AcquireThenRusqliteError>
pub async fn finalize_block( &self, block_ca: ContentAddress, ) -> Result<(), AcquireThenRusqliteError>
Finalizes the block with the given hash. This sets the block to be the only block at a particular block number.
sourcepub async fn update_state(
&self,
contract_ca: ContentAddress,
key: Key,
value: Value,
) -> Result<(), AcquireThenRusqliteError>
pub async fn update_state( &self, contract_ca: ContentAddress, key: Key, value: Value, ) -> Result<(), AcquireThenRusqliteError>
Updates the state for a given contract content address and key.
sourcepub async fn delete_state(
&self,
contract_ca: ContentAddress,
key: Key,
) -> Result<(), AcquireThenRusqliteError>
pub async fn delete_state( &self, contract_ca: ContentAddress, key: Key, ) -> Result<(), AcquireThenRusqliteError>
Deletes the state for a given contract content address and key.
sourcepub async fn get_solution(
&self,
ca: ContentAddress,
) -> Result<Option<Solution>, AcquireThenQueryError>
pub async fn get_solution( &self, ca: ContentAddress, ) -> Result<Option<Solution>, AcquireThenQueryError>
Fetches a solution by its content address.
sourcepub async fn query_state(
&self,
contract_ca: ContentAddress,
key: Key,
) -> Result<Option<Value>, AcquireThenQueryError>
pub async fn query_state( &self, contract_ca: ContentAddress, key: Key, ) -> Result<Option<Value>, AcquireThenQueryError>
Fetches the state value for the given contract content address and key pair.
sourcepub async fn get_state_progress(
&self,
) -> Result<Option<ContentAddress>, AcquireThenQueryError>
pub async fn get_state_progress( &self, ) -> Result<Option<ContentAddress>, AcquireThenQueryError>
Get the state progress, returning the last block hash.
sourcepub async fn get_validation_progress(
&self,
) -> Result<Option<ContentAddress>, AcquireThenQueryError>
pub async fn get_validation_progress( &self, ) -> Result<Option<ContentAddress>, AcquireThenQueryError>
Get the validation progress, returning the last block hash.
sourcepub async fn update_validation_progress(
&self,
block_ca: ContentAddress,
) -> Result<(), AcquireThenRusqliteError>
pub async fn update_validation_progress( &self, block_ca: ContentAddress, ) -> Result<(), AcquireThenRusqliteError>
Update the validation progress to point to the block with the given CA.
sourcepub async fn list_blocks(
&self,
block_range: Range<Word>,
) -> Result<Vec<Block>, AcquireThenQueryError>
pub async fn list_blocks( &self, block_range: Range<Word>, ) -> Result<Vec<Block>, AcquireThenQueryError>
Lists all blocks in the given range.
sourcepub async fn list_blocks_by_time(
&self,
range: Range<Duration>,
page_size: i64,
page_number: i64,
) -> Result<Vec<Block>, AcquireThenQueryError>
pub async fn list_blocks_by_time( &self, range: Range<Duration>, page_size: i64, page_number: i64, ) -> Result<Vec<Block>, AcquireThenQueryError>
Lists blocks and their solutions within a specific time range with pagination.
sourcepub fn subscribe_blocks(
&self,
start_block: Word,
await_new_block: impl AwaitNewBlock,
) -> impl Stream<Item = Result<Block, QueryError>>
pub fn subscribe_blocks( &self, start_block: Word, await_new_block: impl AwaitNewBlock, ) -> impl Stream<Item = Result<Block, QueryError>>
Subscribe to all blocks from the given starting block number.
Trait Implementations§
source§impl AcquireConnection for ConnectionPool
impl AcquireConnection for ConnectionPool
source§async fn acquire_connection(&self) -> Option<impl 'static + AsRef<Connection>>
async fn acquire_connection(&self) -> Option<impl 'static + AsRef<Connection>>
Connection
. Read moresource§impl Clone for ConnectionPool
impl Clone for ConnectionPool
source§fn clone(&self) -> ConnectionPool
fn clone(&self) -> ConnectionPool
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for ConnectionPool
impl !RefUnwindSafe for ConnectionPool
impl Send for ConnectionPool
impl Sync for ConnectionPool
impl Unpin for ConnectionPool
impl !UnwindSafe for ConnectionPool
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more