Skip to main content

PGConnection

Enum PGConnection 

Source
pub enum PGConnection {
    Pool(Pool<Postgres>, Cache<VersionId, Resource>),
    Transaction(Arc<Mutex<Transaction<'static, Postgres>>>, Cache<VersionId, Resource>, PendingRows),
}
Expand description

Connection types supported by the repository traits.

Variants§

§

Pool(Pool<Postgres>, Cache<VersionId, Resource>)

§

Transaction(Arc<Mutex<Transaction<'static, Postgres>>>, Cache<VersionId, Resource>, PendingRows)

Implementations§

Source§

impl PGConnection

Source

pub fn pool(pool: Pool<Postgres>) -> Self

Source

pub fn cache(&self) -> &Cache<VersionId, Resource>

Trait Implementations§

Source§

impl AsyncJobProvider for PGConnection

Source§

async fn create_job( &self, tenant: &TenantId, project: &ProjectId, job: CreateAsyncJob, ) -> Result<AsyncJob, OperationOutcomeError>

Queues a job. Its id is generated here and is what the status URL carries.
Source§

async fn read_job( &self, tenant: &TenantId, project: &ProjectId, id: &str, ) -> Result<Option<AsyncJob>, OperationOutcomeError>

A job of this project, whatever its state, until it expires.
Source§

async fn count_live_jobs( &self, tenant: &TenantId, project: &ProjectId, ) -> Result<i64, OperationOutcomeError>

Jobs of this project that are queued or running. Kick-offs cap this.
Source§

async fn cancel_job( &self, tenant: &TenantId, project: &ProjectId, id: &str, ) -> Result<Option<AsyncJob>, OperationOutcomeError>

Cancels a job of this project. A queued job never runs; a running one finds out at its next lease renewal; a finished one gives up its result. Returns the job as it was before, or None if there is no such job or it was already cancelled.
Source§

async fn claim_job( &self, kinds: &[&str], lease: &JobLease, ) -> Result<Option<AsyncJob>, OperationOutcomeError>

Takes the oldest claimable job of one of kinds for lease.worker: queued, or in progress with a lapsed lease, and with attempts left. Claiming is one statement, so two workers never take the same job.
Source§

async fn renew_lease( &self, id: &str, lease: &JobLease, progress: Option<&str>, ) -> Result<LeaseRenewal, OperationOutcomeError>

Extends the lease on a job this worker holds and records progress if given. Lost means stop: the job was cancelled or taken over.
Source§

async fn finish_job( &self, id: &str, worker: &str, result: JobResult, retention: Duration, ) -> Result<bool, OperationOutcomeError>

Records the result of a job this worker holds and releases the lease. Returns false if the job was no longer this worker’s to finish (it was cancelled or taken over meanwhile), in which case the result is dropped.
Source§

async fn fail_abandoned_jobs( &self, outcome: &Value, retention: Duration, ) -> Result<u64, OperationOutcomeError>

Fails every in-progress job whose lease has lapsed and that has no attempts left, recording outcome on each. Returns how many.
Source§

async fn delete_expired_jobs( &self, limit: i64, ) -> Result<Vec<AsyncJob>, OperationOutcomeError>

Removes every job past its expires_at, returning them so their handlers can remove what they produced.
Source§

impl Clone for PGConnection

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PGConnection

Source§

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

Formats the value using the given formatter. Read more
Source§

impl FHIRRepository for PGConnection

Source§

async fn create( &self, tenant: &TenantId, project: &ProjectId, author: &UserTokenClaims, fhir_version: &SupportedFHIRVersions, resource: Resource, ) -> Result<Resource, OperationOutcomeError>

Source§

async fn delete( &self, tenant: &TenantId, project: &ProjectId, author: &UserTokenClaims, fhir_version: &SupportedFHIRVersions, resource: Resource, id: &str, ) -> Result<Resource, OperationOutcomeError>

Source§

async fn update( &self, tenant: &TenantId, project: &ProjectId, author: &UserTokenClaims, fhir_version: &SupportedFHIRVersions, resource: Resource, id: &str, ) -> Result<Resource, OperationOutcomeError>

Source§

async fn read_by_version_ids( &self, tenant_id: &TenantId, project_id: &ProjectId, version_ids: &[&VersionId], cache_policy: CachePolicy, ) -> Result<Vec<Resource>, OperationOutcomeError>

Source§

async fn read_latest( &self, tenant_id: &TenantId, project_id: &ProjectId, resource_type: &ResourceType, resource_id: &ResourceId, ) -> Result<Option<Resource>, OperationOutcomeError>

Source§

async fn read_latest_many( &self, tenant_id: &TenantId, project_id: &ProjectId, keys: &[(ResourceType, ResourceId)], ) -> Result<Vec<Resource>, OperationOutcomeError>

Self::read_latest for many keys in one round trip: the current version of each (type, id) that exists and is not deleted, in no particular order. A key that does not resolve is left out.
Source§

async fn history( &self, tenant_id: &TenantId, project_id: &ProjectId, request: &HistoryRequest, ) -> Result<Vec<ResourceHistoryValue>, OperationOutcomeError>

Source§

fn in_transaction(&self) -> bool

Source§

async fn transaction( &self, is_updating_sequence: bool, ) -> Result<Self, OperationOutcomeError>

Source§

async fn commit(self) -> Result<(), OperationOutcomeError>

Source§

async fn rollback(self) -> Result<(), OperationOutcomeError>

Source§

impl FailedIndexingProvider for PGConnection

Source§

async fn record_failures( &self, failures: &[FailedIndexRecord], ) -> Result<(), OperationOutcomeError>

Durably records resources that failed search indexing so they can be skipped (instead of retried forever) and inspected later. No-op on an empty list.
Source§

async fn search( &self, tenant: &TenantId, project: &ProjectId, ) -> Result<Vec<FailedIndexEntry>, OperationOutcomeError>

Lists recorded indexing failures for a tenant/project, most recently failed first.
Source§

impl Login for PGConnection

Source§

async fn login( &self, tenant: &TenantId, method: &LoginMethod, ) -> Result<LoginResult, OperationOutcomeError>

Source§

impl Migrate for PGConnection

Source§

async fn migrate(&self) -> Result<(), OperationOutcomeError>

Source§

impl<Key: AsRef<str> + Send + Sync> ProjectModelAdmin<CreateAuthorizationCode, AuthorizationCode, AuthorizationCodeSearchClaims, AuthorizationCode, Key> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, project: &ProjectId, authorization_code: CreateAuthorizationCode, ) -> Result<AuthorizationCode, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, project: &ProjectId, code: &Key, ) -> Result<Option<AuthorizationCode>, OperationOutcomeError>

Source§

fn update( &self, _tenant: &TenantId, _project: &ProjectId, _model: AuthorizationCode, ) -> impl Future<Output = Result<AuthorizationCode, OperationOutcomeError>>

Source§

async fn delete( &self, tenant: &TenantId, project: &ProjectId, code: &Key, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, project: &ProjectId, clauses: &AuthorizationCodeSearchClaims, ) -> Result<Vec<AuthorizationCode>, OperationOutcomeError>

Source§

impl<Key: AsRef<str> + Send + Sync> ProjectModelAdmin<CreateMembership, Membership, MembershipSearchClaims, Membership, Key> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, project: &ProjectId, new_membership: CreateMembership, ) -> Result<Membership, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, project: &ProjectId, id: &Key, ) -> Result<Option<Membership>, OperationOutcomeError>

Source§

async fn update( &self, tenant: &TenantId, project: &ProjectId, model: Membership, ) -> Result<Membership, OperationOutcomeError>

Source§

async fn delete( &self, tenant: &TenantId, project: &ProjectId, id: &Key, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, project: &ProjectId, clauses: &MembershipSearchClaims, ) -> Result<Vec<Membership>, OperationOutcomeError>

Source§

impl ProjectModelAdmin<CreateScope, Scope, ScopeSearchClaims, UpdateScope, ScopeKey> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, project: &ProjectId, new_scope: CreateScope, ) -> Result<Scope, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, project: &ProjectId, key: &ScopeKey, ) -> Result<Option<Scope>, OperationOutcomeError>

Source§

async fn update( &self, tenant: &TenantId, project: &ProjectId, model: UpdateScope, ) -> Result<Scope, OperationOutcomeError>

Source§

async fn delete( &self, tenant: &TenantId, project: &ProjectId, key: &ScopeKey, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, project: &ProjectId, clauses: &ScopeSearchClaims, ) -> Result<Vec<Scope>, OperationOutcomeError>

Source§

impl RateLimit for PGConnection

Source§

fn check<'a>( &'a self, rate_key: &'a str, max: i32, points: i32, window_in_seconds: i32, ) -> Pin<Box<dyn Future<Output = Result<i32, RateLimitError>> + Send + 'a>>

Returns the current points after the operation. Note use of box and pin so can satisfy dynamic dispatch requirements.

Source§

fn check_uncached<'a>( &'a self, rate_key: &'a str, max: i32, points: i32, window_in_seconds: i32, ) -> Pin<Box<dyn Future<Output = Result<i32, RateLimitError>> + Send + 'a>>

Goes straight to Postgres, skipping [MEMORY]. check_rate_limit takes a per-key advisory transaction lock, so concurrent callers are counted one at a time with no lost increments. The in-memory cache is what makes [RateLimit::check] fast but imprecise under a burst; this trades that for an exact count on every call.

Source§

impl Repository for PGConnection

Source§

impl ResourceSequential for PGConnection

Source§

async fn max_safe_sequence(&self) -> Result<i64, OperationOutcomeError>

The highest resources.sequence a consumer may read up to without skipping a row that is still being written: every row at or below it that will ever commit is visible to any snapshot taken after this call returns.
Source§

async fn get_sequence( &self, tenant_id: &TenantId, project_id: &ProjectId, sequence_id: u64, safe_sequence: i64, count: Option<u64>, ) -> Result<Vec<ResourcePollingValue>, OperationOutcomeError>

The project’s rows with sequence_id < sequence <= safe_sequence, in sequence order. safe_sequence must come from a max_safe_sequence call that returned before this query’s snapshot was taken.
Source§

impl SystemAdmin<User, UserSearchClauses> for PGConnection

Source§

async fn search( &self, clauses: &UserSearchClauses, ) -> Result<Vec<User>, OperationOutcomeError>

Source§

impl<Key: AsRef<str> + Send + Sync> TenantModelAdmin<CreateAuthorizationCode, AuthorizationCode, AuthorizationCodeSearchClaims, AuthorizationCode, Key> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, authorization_code: CreateAuthorizationCode, ) -> Result<AuthorizationCode, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, code: &Key, ) -> Result<Option<AuthorizationCode>, OperationOutcomeError>

Source§

fn update( &self, _tenant: &TenantId, _model: AuthorizationCode, ) -> impl Future<Output = Result<AuthorizationCode, OperationOutcomeError>>

Source§

async fn delete( &self, tenant: &TenantId, code: &Key, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, clauses: &AuthorizationCodeSearchClaims, ) -> Result<Vec<AuthorizationCode>, OperationOutcomeError>

Source§

impl<Key: AsRef<str> + Send + Sync> TenantModelAdmin<CreateProject, Project, ProjectSearchClaims, Project, Key> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, new_project: CreateProject, ) -> Result<Project, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, id: &Key, ) -> Result<Option<Project>, OperationOutcomeError>

Source§

async fn update( &self, tenant: &TenantId, model: Project, ) -> Result<Project, OperationOutcomeError>

Source§

async fn delete( &self, tenant: &TenantId, id: &Key, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, claims: &ProjectSearchClaims, ) -> Result<Vec<Project>, OperationOutcomeError>

Source§

impl<Key: AsRef<str> + Send + Sync> TenantModelAdmin<CreateTenant, Tenant, TenantSearchClaims, Tenant, Key> for PGConnection

Source§

async fn create( &self, _tenant: &TenantId, new_tenant: CreateTenant, ) -> Result<Tenant, OperationOutcomeError>

Source§

async fn read( &self, _tenant: &TenantId, id: &Key, ) -> Result<Option<Tenant>, OperationOutcomeError>

Source§

async fn update( &self, _tenant: &TenantId, model: Tenant, ) -> Result<Tenant, OperationOutcomeError>

Source§

async fn delete( &self, _tenant: &TenantId, id: &Key, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, _tenant: &TenantId, claims: &TenantSearchClaims, ) -> Result<Vec<Tenant>, OperationOutcomeError>

Source§

impl<Key: AsRef<str> + Send + Sync> TenantModelAdmin<CreateUser, User, UserSearchClauses, UpdateUser, Key> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, new_user: CreateUser, ) -> Result<User, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, id: &Key, ) -> Result<Option<User>, OperationOutcomeError>

Source§

async fn update( &self, tenant: &TenantId, user: UpdateUser, ) -> Result<User, OperationOutcomeError>

Source§

async fn delete( &self, tenant: &TenantId, id: &Key, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, clauses: &UserSearchClauses, ) -> Result<Vec<User>, OperationOutcomeError>

Source§

impl TenantModelAdmin<UserMFACredentialCreate, UserMFACredential, UserMFASearchClaims, UserMFACredentialUpdate, MFAKey> for PGConnection

Source§

async fn create( &self, tenant: &TenantId, new_user_mfa_credential: UserMFACredentialCreate, ) -> Result<UserMFACredential, OperationOutcomeError>

Source§

async fn read( &self, tenant: &TenantId, id: &MFAKey, ) -> Result<Option<UserMFACredential>, OperationOutcomeError>

Source§

async fn update( &self, tenant: &TenantId, model: UserMFACredentialUpdate, ) -> Result<UserMFACredential, OperationOutcomeError>

Source§

async fn delete( &self, tenant: &TenantId, id: &MFAKey, ) -> Result<(), OperationOutcomeError>

Source§

async fn search( &self, tenant: &TenantId, claims: &UserMFASearchClaims, ) -> Result<Vec<UserMFACredential>, OperationOutcomeError>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

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

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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