pub struct Database {
pub db: Arc<ConnectionThreadSafe>,
}
Expand description
A file-backed database storing information about the network.
Fields§
§db: Arc<ConnectionThreadSafe>
Implementations§
Source§impl Database
impl Database
Sourcepub fn open<P>(path: P) -> Result<Database, Error>
pub fn open<P>(path: P) -> Result<Database, Error>
Open a database at the given path. Creates a new database if it doesn’t exist.
Sourcepub fn reader<P>(path: P) -> Result<Database, Error>
pub fn reader<P>(path: P) -> Result<Database, Error>
Same as Self::open
, but in read-only mode. This is useful to have multiple
open databases, as no locking is required.
Sourcepub fn journal_mode(self, mode: JournalMode) -> Result<Database, Error>
pub fn journal_mode(self, mode: JournalMode) -> Result<Database, Error>
Set journal mode.
Sourcepub fn init<'a>(
self,
node: &PublicKey,
features: Features,
alias: &Alias,
agent: &UserAgent,
timestamp: Timestamp,
addrs: impl IntoIterator<Item = &'a Address>,
) -> Result<Database, Error>
pub fn init<'a>( self, node: &PublicKey, features: Features, alias: &Alias, agent: &UserAgent, timestamp: Timestamp, addrs: impl IntoIterator<Item = &'a Address>, ) -> Result<Database, Error>
Initialize by adding our local node to the database.
Methods from Deref<Target = Connection>§
Sourcepub fn execute<T>(&self, statement: T) -> Result<(), Error>
pub fn execute<T>(&self, statement: T) -> Result<(), Error>
Execute a statement without processing the resulting rows if any.
Sourcepub fn iterate<T, F>(&self, statement: T, callback: F) -> Result<(), Error>
pub fn iterate<T, F>(&self, statement: T, callback: F) -> Result<(), Error>
Execute a statement and process the resulting rows as plain text.
The callback is triggered for each row. If the callback returns false
, no more rows will
be processed. For large queries and non-string data types, prepared statement are highly
preferable; see prepare
.
Sourcepub fn prepare<T>(&self, statement: T) -> Result<Statement<'_>, Error>
pub fn prepare<T>(&self, statement: T) -> Result<Statement<'_>, Error>
Create a prepared statement.
Sourcepub fn set_busy_handler<F>(&mut self, callback: F) -> Result<(), Error>
pub fn set_busy_handler<F>(&mut self, callback: F) -> Result<(), Error>
Set a callback for handling busy events.
The callback is triggered when the database cannot perform an operation due to processing
of some other request. If the callback returns true
, the operation will be repeated.
Sourcepub fn set_busy_timeout(&mut self, milliseconds: usize) -> Result<(), Error>
pub fn set_busy_timeout(&mut self, milliseconds: usize) -> Result<(), Error>
Set an implicit callback for handling busy events that tries to repeat rejected operations until a timeout expires.
Sourcepub fn remove_busy_handler(&mut self) -> Result<(), Error>
pub fn remove_busy_handler(&mut self) -> Result<(), Error>
Remove the callback handling busy events.
Sourcepub fn change_count(&self) -> usize
pub fn change_count(&self) -> usize
Return the number of rows inserted, updated, or deleted by the most recent INSERT, UPDATE, or DELETE statement.
Sourcepub fn total_change_count(&self) -> usize
pub fn total_change_count(&self) -> usize
Return the total number of rows inserted, updated, and deleted by all INSERT, UPDATE, and DELETE statements since the connection was opened.
Trait Implementations§
Source§impl From<ConnectionThreadSafe> for Database
impl From<ConnectionThreadSafe> for Database
Source§fn from(db: ConnectionThreadSafe) -> Database
fn from(db: ConnectionThreadSafe) -> Database
Source§impl Store for Database
impl Store for Database
Source§fn get(&self, node: &PublicKey) -> Result<Option<Node>, Error>
fn get(&self, node: &PublicKey) -> Result<Option<Node>, Error>
Source§fn is_addr_banned(&self, addr: &Address) -> Result<bool, Error>
fn is_addr_banned(&self, addr: &Address) -> Result<bool, Error>
true
if the node this address belongs
to is banned.Source§fn addresses_of(&self, node: &PublicKey) -> Result<Vec<KnownAddress>, Error>
fn addresses_of(&self, node: &PublicKey) -> Result<Vec<KnownAddress>, Error>
Source§fn insert(
&mut self,
node: &PublicKey,
version: u8,
features: Features,
alias: &Alias,
pow: u32,
agent: &UserAgent,
timestamp: Timestamp,
addrs: impl IntoIterator<Item = KnownAddress>,
) -> Result<bool, Error>
fn insert( &mut self, node: &PublicKey, version: u8, features: Features, alias: &Alias, pow: u32, agent: &UserAgent, timestamp: Timestamp, addrs: impl IntoIterator<Item = KnownAddress>, ) -> Result<bool, Error>
Source§fn entries(&self) -> Result<Box<dyn Iterator<Item = AddressEntry>>, Error>
fn entries(&self) -> Result<Box<dyn Iterator<Item = AddressEntry>>, Error>
Source§fn attempted(
&self,
nid: &PublicKey,
addr: &Address,
time: Timestamp,
) -> Result<(), Error>
fn attempted( &self, nid: &PublicKey, addr: &Address, time: Timestamp, ) -> Result<(), Error>
Source§fn connected(
&self,
nid: &PublicKey,
addr: &Address,
time: Timestamp,
) -> Result<(), Error>
fn connected( &self, nid: &PublicKey, addr: &Address, time: Timestamp, ) -> Result<(), Error>
Source§fn record_ip(
&self,
nid: &PublicKey,
ip: IpAddr,
time: Timestamp,
) -> Result<(), Error>
fn record_ip( &self, nid: &PublicKey, ip: IpAddr, time: Timestamp, ) -> Result<(), Error>
Source§impl Store for Database
impl Store for Database
Source§fn set(
&mut self,
repo: &RepoId,
namespace: &PublicKey,
refname: &Qualified<'_>,
oid: Oid,
timestamp: LocalTime,
) -> Result<bool, Error>
fn set( &mut self, repo: &RepoId, namespace: &PublicKey, refname: &Qualified<'_>, oid: Oid, timestamp: LocalTime, ) -> Result<bool, Error>
Oid
.Source§fn get(
&self,
repo: &RepoId,
namespace: &PublicKey,
refname: &Qualified<'_>,
) -> Result<Option<(Oid, LocalTime)>, Error>
fn get( &self, repo: &RepoId, namespace: &PublicKey, refname: &Qualified<'_>, ) -> Result<Option<(Oid, LocalTime)>, Error>
Oid
and timestamp.Source§fn delete(
&mut self,
repo: &RepoId,
namespace: &PublicKey,
refname: &Qualified<'_>,
) -> Result<bool, Error>
fn delete( &mut self, repo: &RepoId, namespace: &PublicKey, refname: &Qualified<'_>, ) -> Result<bool, Error>
Source§impl Store for Database
impl Store for Database
Source§fn get(&self, id: &RepoId) -> Result<HashSet<PublicKey>, Error>
fn get(&self, id: &RepoId) -> Result<HashSet<PublicKey>, Error>
Source§fn get_inventory(&self, node: &PublicKey) -> Result<HashSet<RepoId>, Error>
fn get_inventory(&self, node: &PublicKey) -> Result<HashSet<RepoId>, Error>
Source§fn entry(
&self,
id: &RepoId,
node: &PublicKey,
) -> Result<Option<Timestamp>, Error>
fn entry( &self, id: &RepoId, node: &PublicKey, ) -> Result<Option<Timestamp>, Error>
Source§fn add_inventory<'a>(
&mut self,
ids: impl IntoIterator<Item = &'a RepoId>,
node: PublicKey,
time: Timestamp,
) -> Result<Vec<(RepoId, InsertResult)>, Error>
fn add_inventory<'a>( &mut self, ids: impl IntoIterator<Item = &'a RepoId>, node: PublicKey, time: Timestamp, ) -> Result<Vec<(RepoId, InsertResult)>, Error>
Source§fn entries(
&self,
) -> Result<Box<dyn Iterator<Item = (RepoId, PublicKey)>>, Error>
fn entries( &self, ) -> Result<Box<dyn Iterator<Item = (RepoId, PublicKey)>>, Error>
Source§fn remove_inventory(
&mut self,
id: &RepoId,
node: &PublicKey,
) -> Result<bool, Error>
fn remove_inventory( &mut self, id: &RepoId, node: &PublicKey, ) -> Result<bool, Error>
Source§fn remove_inventories<'a>(
&mut self,
rids: impl IntoIterator<Item = &'a RepoId>,
nid: &PublicKey,
) -> Result<(), Error>
fn remove_inventories<'a>( &mut self, rids: impl IntoIterator<Item = &'a RepoId>, nid: &PublicKey, ) -> Result<(), Error>
Source§fn prune(
&mut self,
oldest: Timestamp,
limit: Option<usize>,
ignore: &PublicKey,
) -> Result<usize, Error>
fn prune( &mut self, oldest: Timestamp, limit: Option<usize>, ignore: &PublicKey, ) -> Result<usize, Error>
Source§impl Store for Database
impl Store for Database
Source§fn synced(
&mut self,
rid: &RepoId,
nid: &PublicKey,
at: Oid,
timestamp: Timestamp,
) -> Result<bool, Error>
fn synced( &mut self, rid: &RepoId, nid: &PublicKey, at: Oid, timestamp: Timestamp, ) -> Result<bool, Error>
Source§impl Store for Database
impl Store for Database
Source§fn prune(&mut self, cutoff: Timestamp) -> Result<usize, Error>
fn prune(&mut self, cutoff: Timestamp) -> Result<usize, Error>
Source§fn last(&self) -> Result<Option<Timestamp>, Error>
fn last(&self) -> Result<Option<Timestamp>, Error>
Source§fn announced(
&mut self,
nid: &PublicKey,
ann: &Announcement,
) -> Result<Option<u64>, Error>
fn announced( &mut self, nid: &PublicKey, ann: &Announcement, ) -> Result<Option<u64>, Error>
true
if the timestamp was updated or the announcement wasn’t there before.Source§fn set_relay(&mut self, id: u64, relay: RelayStatus) -> Result<(), Error>
fn set_relay(&mut self, id: u64, relay: RelayStatus) -> Result<(), Error>
impl Store for Database
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> AliasStore for T
impl<T> AliasStore for T
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§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