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.
Note that this function does not initialise the node DB tables by default. See the
ConnectionPool::with_tables
constructor.
Sourcepub fn with_tables(conf: &Config) -> Result<Self>
pub fn with_tables(conf: &Config) -> Result<Self>
Create the connection pool from the given configuration and ensure the DB tables have been created if they do not already exist before returning.
## Example
let conf = essential_node_db::pool::Config::default();
let db = essential_node_db::ConnectionPool::with_tables(&conf).unwrap();
for block in db.list_blocks(0..100).await.unwrap() {
println!("Block: {block:?}");
}
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
Short-hand methods for async DB access.
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
solution sets, add a row into the solution_set
and block_solution_set
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_block(
&self,
block_address: ContentAddress,
) -> Result<Option<Block>, AcquireThenQueryError>
pub async fn get_block( &self, block_address: ContentAddress, ) -> Result<Option<Block>, AcquireThenQueryError>
Fetches a block by its hash.
Sourcepub async fn get_solution_set(
&self,
ca: ContentAddress,
) -> Result<SolutionSet, AcquireThenQueryError>
pub async fn get_solution_set( &self, ca: ContentAddress, ) -> Result<SolutionSet, AcquireThenQueryError>
Fetches a solution set 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 query_latest_finalized_block(
&self,
contract_ca: ContentAddress,
key: Key,
) -> Result<Option<Value>, AcquireThenQueryError>
pub async fn query_latest_finalized_block( &self, contract_ca: ContentAddress, key: Key, ) -> Result<Option<Value>, AcquireThenQueryError>
Fetches the state value for the given contract content address and key pair within a range of blocks.
Sourcepub async fn query_state_finalized_inclusive_block(
&self,
contract_ca: ContentAddress,
key: Key,
block_number: Word,
) -> Result<Option<Value>, AcquireThenQueryError>
pub async fn query_state_finalized_inclusive_block( &self, contract_ca: ContentAddress, key: Key, block_number: Word, ) -> Result<Option<Value>, AcquireThenQueryError>
Fetches the state value for the given contract content address and key pair
within a range of blocks inclusive. ..=block
.
Sourcepub async fn query_state_finalized_exclusive_block(
&self,
contract_ca: ContentAddress,
key: Key,
block_number: Word,
) -> Result<Option<Value>, AcquireThenQueryError>
pub async fn query_state_finalized_exclusive_block( &self, contract_ca: ContentAddress, key: Key, block_number: Word, ) -> Result<Option<Value>, AcquireThenQueryError>
Fetches the state value for the given contract content address and key pair
within a range of blocks exclusive. ..block
.
Sourcepub async fn query_state_finalized_inclusive_solution_set(
&self,
contract_ca: ContentAddress,
key: Key,
block_number: Word,
solution_set_ix: u64,
) -> Result<Option<Value>, AcquireThenQueryError>
pub async fn query_state_finalized_inclusive_solution_set( &self, contract_ca: ContentAddress, key: Key, block_number: Word, solution_set_ix: u64, ) -> Result<Option<Value>, AcquireThenQueryError>
Fetches the state value for the given contract content address and key pair
within a range of blocks and solution sets inclusive. ..block[..=solution_set]
.
Sourcepub async fn query_state_finalized_exclusive_solution_set(
&self,
contract_ca: ContentAddress,
key: Key,
block_number: Word,
solution_set_ix: u64,
) -> Result<Option<Value>, AcquireThenQueryError>
pub async fn query_state_finalized_exclusive_solution_set( &self, contract_ca: ContentAddress, key: Key, block_number: Word, solution_set_ix: u64, ) -> Result<Option<Value>, AcquireThenQueryError>
Fetches the state value for the given contract content address and key pair
within a range of blocks and solution sets exclusive. ..=block[..solution_set]
.
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 get_next_block_addresses(
&self,
current_block: ContentAddress,
) -> Result<Vec<ContentAddress>, AcquireThenQueryError>
pub async fn get_next_block_addresses( &self, current_block: ContentAddress, ) -> Result<Vec<ContentAddress>, AcquireThenQueryError>
Get next block(s) given the current 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 solution sets 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 + AsMut<Connection>>
async fn acquire_connection(&self) -> Option<impl 'static + AsMut<Connection>>
Connection
. Read moreSource§impl AsRef<AsyncConnectionPool> for ConnectionPool
impl AsRef<AsyncConnectionPool> for ConnectionPool
Source§fn as_ref(&self) -> &AsyncConnectionPool
fn as_ref(&self) -> &AsyncConnectionPool
Source§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 more