pub struct Db { /* private fields */ }Expand description
A connection pool plus the dynamic CRUD executor.
Implementations§
Source§impl Db
impl Db
Sourcepub async fn connect(url: &str, max_connections: u32) -> Result<Self, Error>
pub async fn connect(url: &str, max_connections: u32) -> Result<Self, Error>
Open a pool against the given Postgres URL, creating the database first if it does not exist yet.
A fresh checkout pointed at a running Postgres would otherwise fail with
database "…" does not exist before migrations ever get a chance to
run, so on that specific error we connect to the postgres maintenance
database on the same server, CREATE DATABASE, and retry once. Any
other failure (bad credentials, no server) is returned untouched.
Sourcepub fn connection(&self) -> &DatabaseConnection
pub fn connection(&self) -> &DatabaseConnection
Access the underlying connection (used by [migrate]).
Sourcepub async fn list(
&self,
r: &Resource,
filters: &[Filter],
limit: i64,
offset: i64,
) -> Result<Value, Error>
pub async fn list( &self, r: &Resource, filters: &[Filter], limit: i64, offset: i64, ) -> Result<Value, Error>
GET /<resource> — a JSON array of rows, newest first.
Sourcepub async fn get(
&self,
r: &Resource,
id: Uuid,
filters: &[Filter],
) -> Result<Option<Value>, Error>
pub async fn get( &self, r: &Resource, id: Uuid, filters: &[Filter], ) -> Result<Option<Value>, Error>
GET /<resource>/<id> — one row or None.
Sourcepub async fn create(
&self,
r: &Resource,
data: &Map<String, Value>,
) -> Result<Value, Error>
pub async fn create( &self, r: &Resource, data: &Map<String, Value>, ) -> Result<Value, Error>
POST /<resource> — insert and return the created row.
Sourcepub async fn update(
&self,
r: &Resource,
id: Uuid,
data: &Map<String, Value>,
filters: &[Filter],
) -> Result<Option<Value>, Error>
pub async fn update( &self, r: &Resource, id: Uuid, data: &Map<String, Value>, filters: &[Filter], ) -> Result<Option<Value>, Error>
PATCH /<resource>/<id> — update present fields, return the new row.
Sourcepub async fn delete(
&self,
r: &Resource,
id: Uuid,
filters: &[Filter],
) -> Result<bool, Error>
pub async fn delete( &self, r: &Resource, id: Uuid, filters: &[Filter], ) -> Result<bool, Error>
DELETE /<resource>/<id> — returns whether a row was removed.
Sourcepub async fn fetch_by_ids(
&self,
r: &Resource,
ids: &[Uuid],
filters: &[Filter],
) -> Result<Value, Error>
pub async fn fetch_by_ids( &self, r: &Resource, ids: &[Uuid], filters: &[Filter], ) -> Result<Value, Error>
Fetch multiple rows of a resource by id (used for relation expansion).
filters carry the caller’s authorization scope, so an expansion can
never reach a row a direct read would have refused. Returns a JSON array
with hidden fields stripped; order is unspecified.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Db
impl !UnwindSafe for Db
impl Freeze for Db
impl Send for Db
impl Sync for Db
impl Unpin for Db
impl UnsafeUnpin for Db
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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