pub struct PowerSyncDatabase { /* private fields */ }Implementations§
Source§impl PowerSyncDatabase
An opened database managed by the PowerSync SDK.
impl PowerSyncDatabase
An opened database managed by the PowerSync SDK.
To run SQL statements against this database, use Self::reader and Self::writer.
To connect to a PowerSync service, first call [Self::download_actor] and [Self::upload_actor] and have those futures be polled by an async runtime of your choice. They will run as long as the database is active. Then, call Self::connect to establish a connection to the PowerSync service.
pub fn new(env: PowerSyncEnvironment, schema: Schema) -> Self
Sourcepub fn async_tasks(&self) -> AsyncDatabaseTasks
pub fn async_tasks(&self) -> AsyncDatabaseTasks
Returns a collection of [AsyncDatabaseTasks] that need to be started before connecting this PowerSync database to a PowerSync service.
To start the tasks, see the documentation on [AsyncDatabaseTasks].
By exposing these async tasks instead of starting them automatically, the SDK stays executor-agnostic and is easier to access from C.
Sourcepub async fn connect(&self, options: SyncOptions)
pub async fn connect(&self, options: SyncOptions)
Requests the download actor, started with [Self::download_actor], to start establishing a connection to the PowerSync service.
Sourcepub async fn disconnect(&self)
pub async fn disconnect(&self)
If the sync client is currently connected, requests it to disconnect.
Sourcepub fn watch_tables<'a, Tables: IntoIterator<Item = impl Into<Cow<'a, str>>>>(
&self,
emit_initially: bool,
tables: Tables,
) -> impl Stream<Item = ()> + 'static
pub fn watch_tables<'a, Tables: IntoIterator<Item = impl Into<Cow<'a, str>>>>( &self, emit_initially: bool, tables: Tables, ) -> impl Stream<Item = ()> + 'static
Returns an asynchronous Stream emitting an empty event every time one of the specified tables is written to.
The emit_initially option can be used to control whether the stream should emit as well
when polled for the first time. This can be useful to build streams emitting a complete
snapshot of results every time a source table is changed.
Sourcepub fn watch_statement<T, F, P: Params + Clone + 'static>(
&self,
sql: String,
params: P,
read: F,
) -> impl Stream<Item = Result<T, PowerSyncError>> + 'static
pub fn watch_statement<T, F, P: Params + Clone + 'static>( &self, sql: String, params: P, read: F, ) -> impl Stream<Item = Result<T, PowerSyncError>> + 'static
Returns an asynchronous Stream emitting snapshots of a SELECT statement every time
source tables are modified.
sql is the SELECT statement to execute and params are parameters to use.
The read function obtains the raw prepared statement and a copy of parameters to use,
and can run the statements into desired results.
This method is a core building block for reactive applications with PowerSync - since it updates automatically, all writes (regardless of whether they’re local or due to synced writes from your backend) are reflected.
Sourcepub fn crud_transactions<'a>(
&'a self,
) -> impl Stream<Item = Result<CrudTransaction<'a>, PowerSyncError>> + 'a
pub fn crud_transactions<'a>( &'a self, ) -> impl Stream<Item = Result<CrudTransaction<'a>, PowerSyncError>> + 'a
Returns a Stream traversing through transactions that have been completed on this database.
Each CrudTransaction contains all local writes made in that transaction, allowing a backend connector to upload them.
Sourcepub async fn next_crud_transaction<'a>(
&'a self,
) -> Result<Option<CrudTransaction<'a>>, PowerSyncError>
pub async fn next_crud_transaction<'a>( &'a self, ) -> Result<Option<CrudTransaction<'a>>, PowerSyncError>
Returns the first transaction that has not been marked as completed.
This is always the first item of Self::crud_transactions, see that method for details.
Sourcepub fn status(&self) -> Arc<SyncStatusData>
pub fn status(&self) -> Arc<SyncStatusData>
Returns the current SyncStatusData snapshot reporting the sync state of this database.
Sourcepub fn watch_status<'a>(
&'a self,
) -> impl Stream<Item = Arc<SyncStatusData>> + 'a
pub fn watch_status<'a>( &'a self, ) -> impl Stream<Item = Arc<SyncStatusData>> + 'a
Returns an updating Stream of SyncStatusData events emitting every time the status is changed.
Sourcepub fn sync_stream<'a>(
&'a self,
name: &'a str,
parameters: Option<&Value>,
) -> SyncStream<'a>
pub fn sync_stream<'a>( &'a self, name: &'a str, parameters: Option<&Value>, ) -> SyncStream<'a>
Creates a SyncStream based on name and optional parameters.
PowerSync will sync data from the requested stream when calling SyncStream::subscribe. After the subscription handle returned by that method is dropped, PowerSync will continue syncing the stream for a specified amount of time as a local cache.
Sourcepub async fn reader(&self) -> Result<impl LeasedConnection, PowerSyncError>
pub async fn reader(&self) -> Result<impl LeasedConnection, PowerSyncError>
Obtains a LeasedConnection that can be used to run read-only queries on this database.
Sourcepub async fn writer(&self) -> Result<impl LeasedConnection, PowerSyncError>
pub async fn writer(&self) -> Result<impl LeasedConnection, PowerSyncError>
Obtains a LeasedConnection allowing reading and writing queries.
Trait Implementations§
Source§impl Clone for PowerSyncDatabase
impl Clone for PowerSyncDatabase
Source§fn clone(&self) -> PowerSyncDatabase
fn clone(&self) -> PowerSyncDatabase
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more