pub struct PgStore { /* private fields */ }Expand description
PostgreSQL-backed store for sync engine work.
Implementations§
Source§impl PgStore
impl PgStore
Sourcepub async fn advance_checkpoint_if_greater(
&self,
stream_name: impl AsRef<str>,
cursor_position: i64,
cursor: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn advance_checkpoint_if_greater( &self, stream_name: impl AsRef<str>, cursor_position: i64, cursor: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Advances a checkpoint only if the new position is greater than the stored one.
Returns the number of affected rows.
§Errors
Returns an error if the database write fails.
Sourcepub async fn advance_checkpoint_if_greater_in_tx<C>(
client: &C,
stream_name: &str,
cursor_position: i64,
cursor: &str,
) -> Result<u64, ForceSyncError>
pub async fn advance_checkpoint_if_greater_in_tx<C>( client: &C, stream_name: &str, cursor_position: i64, cursor: &str, ) -> Result<u64, ForceSyncError>
Advances a checkpoint in an existing transaction when the position increases.
§Errors
Returns an error if the database write fails.
Sourcepub async fn get_checkpoint(
&self,
stream_name: impl AsRef<str>,
) -> Result<Option<CheckpointState>, ForceSyncError>
pub async fn get_checkpoint( &self, stream_name: impl AsRef<str>, ) -> Result<Option<CheckpointState>, ForceSyncError>
Loads the stored checkpoint for a stream, if one exists.
§Errors
Returns an error if the database query fails.
Source§impl PgStore
impl PgStore
Sourcepub async fn insert_conflict(
&self,
conflict: &SyncConflict,
) -> Result<i64, ForceSyncError>
pub async fn insert_conflict( &self, conflict: &SyncConflict, ) -> Result<i64, ForceSyncError>
Inserts a conflict row and returns its database identifier.
§Errors
Returns an error if the database write fails.
Source§impl PgStore
impl PgStore
Sourcepub async fn insert_dead_letter(
&self,
dead_letter: &DeadLetter,
) -> Result<i64, ForceSyncError>
pub async fn insert_dead_letter( &self, dead_letter: &DeadLetter, ) -> Result<i64, ForceSyncError>
Inserts a dead-letter row and returns its database identifier.
§Errors
Returns an error if the database write fails.
Source§impl PgStore
impl PgStore
Sourcepub async fn append_journal(
&self,
envelope: &ChangeEnvelope,
) -> Result<i64, ForceSyncError>
pub async fn append_journal( &self, envelope: &ChangeEnvelope, ) -> Result<i64, ForceSyncError>
Appends a journal entry and returns its database identifier.
§Errors
Returns an error if the cursor is missing or the database write fails.
Sourcepub async fn append_journal_if_new(
&self,
envelope: &ChangeEnvelope,
) -> Result<AppendResult, ForceSyncError>
pub async fn append_journal_if_new( &self, envelope: &ChangeEnvelope, ) -> Result<AppendResult, ForceSyncError>
Appends a journal entry if the (source, source_cursor) pair is new.
§Errors
Returns an error if the cursor is missing or the database write fails.
Sourcepub async fn append_journal_in_tx<C>(
client: &C,
envelope: &ChangeEnvelope,
) -> Result<i64, ForceSyncError>
pub async fn append_journal_in_tx<C>( client: &C, envelope: &ChangeEnvelope, ) -> Result<i64, ForceSyncError>
Appends a journal row in an existing transaction.
This helper exists so same-transaction workflows can remain atomic without forcing the caller through another store method.
§Errors
Returns an error if the cursor is missing or the database write fails.
Sourcepub async fn append_journal_if_new_in_tx<C>(
client: &C,
envelope: &ChangeEnvelope,
) -> Result<AppendResult, ForceSyncError>
pub async fn append_journal_if_new_in_tx<C>( client: &C, envelope: &ChangeEnvelope, ) -> Result<AppendResult, ForceSyncError>
Appends a journal row in an existing transaction, skipping duplicates.
§Errors
Returns an error if the cursor is missing or the database write fails.
Source§impl PgStore
impl PgStore
Source§impl PgStore
impl PgStore
Sourcepub const fn new(pool: Pool) -> Self
pub const fn new(pool: Pool) -> Self
Creates a new store wrapper around an existing connection pool.
Sourcepub async fn with_client<T, F, Fut>(&self, f: F) -> Result<T, ForceSyncError>
pub async fn with_client<T, F, Fut>(&self, f: F) -> Result<T, ForceSyncError>
Runs an operation against a pooled PostgreSQL client.
§Errors
Returns a pool or query error if the client cannot be acquired or the callback fails.
Sourcepub async fn with_transaction<T, F>(&self, f: F) -> Result<T, ForceSyncError>
pub async fn with_transaction<T, F>(&self, f: F) -> Result<T, ForceSyncError>
Runs an operation inside a PostgreSQL transaction.
§Errors
Returns a pool or query error if the transaction cannot be opened or the callback fails.
Source§impl PgStore
impl PgStore
Sourcepub async fn enqueue_apply_task(
&self,
journal_id: i64,
priority: i32,
) -> Result<i64, ForceSyncError>
pub async fn enqueue_apply_task( &self, journal_id: i64, priority: i32, ) -> Result<i64, ForceSyncError>
Sourcepub async fn lease_ready_tasks(
&self,
worker_id: &str,
limit: i64,
lease_for: Duration,
) -> Result<Vec<LeasedTask>, ForceSyncError>
pub async fn lease_ready_tasks( &self, worker_id: &str, limit: i64, lease_for: Duration, ) -> Result<Vec<LeasedTask>, ForceSyncError>
Leases ready tasks for a worker.
§Errors
Returns an error if the lease duration is invalid or the database write fails.
Sourcepub async fn ack_task(&self, task_id: i64) -> Result<u64, ForceSyncError>
pub async fn ack_task(&self, task_id: i64) -> Result<u64, ForceSyncError>
Acknowledges a completed task administratively, without lease-owner checks.
§Errors
Returns an error if the database write fails.
Sourcepub async fn ack_task_for_worker(
&self,
worker_id: &str,
task_id: i64,
) -> Result<u64, ForceSyncError>
pub async fn ack_task_for_worker( &self, worker_id: &str, task_id: i64, ) -> Result<u64, ForceSyncError>
Acknowledges a completed task for the current lease owner.
Returns 0 if the task is no longer leased by worker_id.
§Errors
Returns an error if the database write fails.
Sourcepub async fn retry_task(
&self,
task_id: i64,
next_attempt_at: DateTime<Utc>,
error: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn retry_task( &self, task_id: i64, next_attempt_at: DateTime<Utc>, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Marks a task for retry at a future time administratively, without lease-owner checks.
§Errors
Returns an error if the database write fails.
Sourcepub async fn retry_task_for_worker(
&self,
worker_id: &str,
task_id: i64,
next_attempt_at: DateTime<Utc>,
error: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn retry_task_for_worker( &self, worker_id: &str, task_id: i64, next_attempt_at: DateTime<Utc>, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Marks a task for retry for the current lease owner.
Returns 0 if the task is no longer leased by worker_id.
§Errors
Returns an error if the database write fails.
Sourcepub async fn fail_task(
&self,
task_id: i64,
error: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn fail_task( &self, task_id: i64, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Marks a task as failed administratively, without lease-owner checks.
§Errors
Returns an error if the database write fails.
Sourcepub async fn fail_task_for_worker(
&self,
worker_id: &str,
task_id: i64,
error: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn fail_task_for_worker( &self, worker_id: &str, task_id: i64, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Marks a task as failed for the current lease owner.
Returns 0 if the task is no longer leased by worker_id.
§Errors
Returns an error if the database write fails.
Sourcepub async fn enqueue_apply_task_in_tx<C>(
client: &C,
journal_id: i64,
priority: i32,
) -> Result<i64, ForceSyncError>
pub async fn enqueue_apply_task_in_tx<C>( client: &C, journal_id: i64, priority: i32, ) -> Result<i64, ForceSyncError>
Enqueues an apply task inside an existing transaction.
§Errors
Returns an error if the database write fails.
Sourcepub async fn lease_ready_tasks_in_tx<C>(
client: &C,
worker_id: &str,
limit: i64,
lease_for: Duration,
) -> Result<Vec<LeasedTask>, ForceSyncError>
pub async fn lease_ready_tasks_in_tx<C>( client: &C, worker_id: &str, limit: i64, lease_for: Duration, ) -> Result<Vec<LeasedTask>, ForceSyncError>
Leases ready tasks inside an existing transaction.
§Errors
Returns an error if the lease duration is invalid or the database write fails.
Sourcepub async fn ack_task_in_tx<C>(
client: &C,
task_id: i64,
) -> Result<u64, ForceSyncError>
pub async fn ack_task_in_tx<C>( client: &C, task_id: i64, ) -> Result<u64, ForceSyncError>
Acknowledges a completed task inside an existing transaction.
§Errors
Returns an error if the database write fails.
Sourcepub async fn retry_task_in_tx<C>(
client: &C,
task_id: i64,
next_attempt_at: DateTime<Utc>,
error: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn retry_task_in_tx<C>( client: &C, task_id: i64, next_attempt_at: DateTime<Utc>, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Marks a task for retry inside an existing transaction.
§Errors
Returns an error if the database write fails.
Sourcepub async fn fail_task_in_tx<C>(
client: &C,
task_id: i64,
error: impl AsRef<str>,
) -> Result<u64, ForceSyncError>
pub async fn fail_task_in_tx<C>( client: &C, task_id: i64, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
Marks a task as failed inside an existing transaction.
§Errors
Returns an error if the database write fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PgStore
impl !RefUnwindSafe for PgStore
impl Send for PgStore
impl Sync for PgStore
impl Unpin for PgStore
impl UnsafeUnpin for PgStore
impl !UnwindSafe for PgStore
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§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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request