Skip to main content

PgStore

Struct PgStore 

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

The store on PostgreSQL, with a connection pool. Send + Sync: share one per process (behind an Arc); each call checks a connection out for its duration.

Every put_* is one transaction. Store methods return errors: a malformed argument is Error::Invalid (no query is made), a database failure Error::Database. The Resolver methods answer both with None; a database failure is logged with tracing (target datumesh_store, level error).

Implementations§

Source§

impl PgStore

Source

pub fn connect(url: &str) -> Result<PgStore>

Connects to a postgres:// URL or key=value connection string, without TLS, with the default PoolOptions. One connection is opened at once, so a wrong URL fails here. For TLS, use with_connector.

Source

pub fn with_connector<F>(connect: F, options: PoolOptions) -> Result<PgStore>
where F: Fn() -> Result<Client, Error> + Send + Sync + 'static,

A store whose pool opens connections with connect (any TLS setup, any configuration). One connection is opened at once, so a failing connector fails here.

Source

pub fn check_statements(&self) -> Result<usize>

Prepares every SQL statement the store uses against the live schema, on a fresh connection’s behalf (no cached statement is reused), and returns how many there are. Fails with the first statement the schema cannot serve.

Trait Implementations§

Source§

impl Debug for PgStore

Source§

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

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

impl Resolver for PgStore

Source§

fn evaluate(&self, cell: &Cell, asof: &str) -> Option<Scalar>

Some only for a stored function (descriptor code.lang is stored, and the store has the descriptor): the value of the receipt of the cell’s latest version with tx <= asof. None for every other function, and when no version is that old.

Source§

fn descriptor(&self, fn_hash: &str) -> Option<Cow<'_, [u8]>>

The descriptor JSON text offered for fn_hash, or None if unavailable (E_FN_UNAVAILABLE).
Source§

fn receipt(&self, hash: &str) -> Option<Cow<'_, [u8]>>

The receipt JSON text offered for receipt hash hash, or None if unavailable (E_INPUT_UNAVAILABLE).
Source§

impl Store for PgStore

Source§

fn put_descriptor(&self, bytes: &[u8]) -> Result<String>

Stores a descriptor (checked and canonicalised by the core); returns its function hash. Idempotent.
Source§

fn put_receipt(&self, bytes: &[u8]) -> Result<String>

Stores a receipt that verifies (SPEC 10.1 steps 1-6) against the key document stored for its signer host with put_namespace, in canonical form, with an edge to each of its inputs; returns its hash. A receipt that does not verify is refused with verify’s code (no key document for the host: E_KEY_UNAVAILABLE). Idempotent: bytes whose canonical form is the stored copy return its hash without checking the signature again (it verified when stored), even if the key has since been revoked. Other bytes with a stored hash are verified first, then refused as Error::Conflict.
Source§

fn put_blob(&self, bytes: &[u8]) -> Result<String>

Stores blob content; returns its SHA-256 (lowercase hex). Idempotent.
Source§

fn blob(&self, sha256: &str) -> Result<Option<Cow<'_, [u8]>>>

Blob content by SHA-256.
Source§

fn put_version(&self, cell_id: &str, tx: &str, receipt_hash: &str) -> Result<()>

Appends a version: from tx on, cell_id has the value of receipt receipt_hash, which must be stored, of that cell and at that tx. tx must be later than the cell’s latest version (Error::NotLater).
Source§

fn version_asof(&self, cell_id: &str, asof: &str) -> Result<Option<Version>>

The cell’s latest version with tx <= asof.
Source§

fn versions(&self, cell_id: &str, from: &str, to: &str) -> Result<Vec<Version>>

The cell’s versions with from <= tx <= to, in tx order.
Source§

fn latest(&self, cell_id: &str) -> Result<Option<Version>>

The cell’s latest version.
Source§

fn dependents(&self, receipt_hash: &str) -> Result<Vec<String>>

The stored receipts that list receipt_hash among their inputs, by hash.
Source§

fn inputs(&self, receipt_hash: &str) -> Result<Vec<String>>

The inputs of a stored receipt, by hash (whether or not they are stored).
Source§

fn put_namespace( &self, host: &str, keydoc_bytes: &[u8], validated_at: &str, ) -> Result<()>

Records a host’s key document, checked as a 200 response for that host would be (SPEC 9.2, 9.3), validated at validated_at. Re-validation replaces the document; a validated_at earlier than the recorded one is Error::NotLater. Receipts already stored are not re-checked: they verified when they were stored (and putting one again stays idempotent).
Source§

fn namespace(&self, host: &str) -> Result<Option<Namespace>>

A host’s recorded key document.
Source§

fn bind_name(&self, fn_name: &str, fn_hash: &str, tx: &str) -> Result<()>

Appends a binding: from tx on, the fully qualified function name fn_name means fn_hash, whose descriptor must be stored. tx must be later than the name’s latest binding (Error::NotLater).
Source§

fn resolve_name(&self, fn_name: &str, asof: &str) -> Result<Option<String>>

The function hash fn_name meant as of asof.

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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.
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