Skip to main content

PgStore

Struct PgStore 

Source
pub struct PgStore { /* private fields */ }
Expand description

PostgreSQL-backed store for sync engine work.

Implementations§

Source§

impl PgStore

Source

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.

Source

pub async fn advance_checkpoint_if_greater_in_tx<C>( client: &C, stream_name: &str, cursor_position: i64, cursor: &str, ) -> Result<u64, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

Advances a checkpoint in an existing transaction when the position increases.

§Errors

Returns an error if the database write fails.

Source

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

Source

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

Source

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

Source

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.

Source

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.

Source

pub async fn append_journal_in_tx<C>( client: &C, envelope: &ChangeEnvelope, ) -> Result<i64, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

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.

Source

pub async fn append_journal_if_new_in_tx<C>( client: &C, envelope: &ChangeEnvelope, ) -> Result<AppendResult, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

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

Upserts a link row and returns the database identifier.

§Errors

Returns an error if the database write fails.

Loads a link row by canonical identity.

§Errors

Returns an error if the database query fails.

Source§

impl PgStore

Source

pub const fn new(pool: Pool) -> Self

Creates a new store wrapper around an existing connection pool.

Source

pub const fn pool(&self) -> &Pool

Returns the backing PostgreSQL pool.

Source

pub async fn with_client<T, F, Fut>(&self, f: F) -> Result<T, ForceSyncError>
where F: FnOnce(Client) -> Fut, Fut: Future<Output = Result<T, Error>>,

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.

Source

pub async fn with_transaction<T, F>(&self, f: F) -> Result<T, ForceSyncError>
where F: for<'a> FnOnce(&'a Transaction<'a>) -> BoxFuture<'a, 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

Source

pub async fn enqueue_apply_task( &self, journal_id: i64, priority: i32, ) -> Result<i64, ForceSyncError>

Enqueues an apply task for a journal row.

§Errors

Returns an error if the database write fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn enqueue_apply_task_in_tx<C>( client: &C, journal_id: i64, priority: i32, ) -> Result<i64, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

Enqueues an apply task inside an existing transaction.

§Errors

Returns an error if the database write fails.

Source

pub async fn lease_ready_tasks_in_tx<C>( client: &C, worker_id: &str, limit: i64, lease_for: Duration, ) -> Result<Vec<LeasedTask>, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

Leases ready tasks inside an existing transaction.

§Errors

Returns an error if the lease duration is invalid or the database write fails.

Source

pub async fn ack_task_in_tx<C>( client: &C, task_id: i64, ) -> Result<u64, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

Acknowledges a completed task inside an existing transaction.

§Errors

Returns an error if the database write fails.

Source

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>
where C: GenericClient + Sync + ?Sized,

Marks a task for retry inside an existing transaction.

§Errors

Returns an error if the database write fails.

Source

pub async fn fail_task_in_tx<C>( client: &C, task_id: i64, error: impl AsRef<str>, ) -> Result<u64, ForceSyncError>
where C: GenericClient + Sync + ?Sized,

Marks a task as failed inside an existing transaction.

§Errors

Returns an error if the database write fails.

Trait Implementations§

Source§

impl Clone for PgStore

Source§

fn clone(&self) -> PgStore

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more