Struct elephantry::Connection[][src]

pub struct Connection { /* fields omitted */ }

A connection to a database.

Implementations

impl Connection[src]

pub fn new(dsn: &str) -> Result<Self>[src]

pub fn async(&self) -> Async<'_>

Notable traits for Async<'c>

impl<'c> Future for Async<'c> type Output = Result<Result>;
[src]

pub fn transaction(&self) -> Transaction<'_>[src]

pub fn from_config(config: &Config) -> Result<Self>[src]

Creates a new connection from Config.

pub fn model<'a, M>(&'a self) -> M where
    M: Model<'a>, 
[src]

pub fn execute(&self, query: &str) -> Result<Result>[src]

Executes a simple text query, without parameter.

pub fn query<E: Entity>(
    &self,
    query: &str,
    params: &[&dyn ToSql]
) -> Result<Rows<E>>
[src]

Executes a simple query, can have parameters.

pub fn query_one<E: Entity>(
    &self,
    query: &str,
    params: &[&dyn ToSql]
) -> Result<E>
[src]

Likes query but peaks only the first result.

pub fn find_by_pk<'a, M>(
    &self,
    pk: &HashMap<&str, &dyn ToSql>
) -> Result<Option<M::Entity>> where
    M: Model<'a>, 
[src]

Return an entity upon its primary key. If no entities are found, None is returned.

pub fn find_all<'a, M>(&self, suffix: Option<&str>) -> Result<Rows<M::Entity>> where
    M: Model<'a>, 
[src]

Return all elements from a relation. If a suffix is given, it is append to the query. This is mainly useful for “order by” statements.

NOTE: suffix is inserted as is with NO ESCAPING. DO NOT use it to place “where” condition nor any untrusted params.

pub fn find_where<'a, M>(
    &self,
    clause: &str,
    params: &[&dyn ToSql],
    suffix: Option<&str>
) -> Result<Rows<M::Entity>> where
    M: Model<'a>, 
[src]

Perform a simple select on a given condition

NOTE: suffix is inserted as is with NO ESCAPING. DO NOT use it to place “where” condition nor any untrusted params.

pub fn paginate_find_where<'a, M>(
    &self,
    clause: &str,
    params: &[&dyn ToSql],
    max_per_page: usize,
    page: usize,
    suffix: Option<&str>
) -> Result<Pager<M::Entity>> where
    M: Model<'a>, 
[src]

Paginate a query.

This is done with limit/offset, read why it’s probably not a good idea to use it: https://use-the-index-luke.com/no-offset.

pub fn count_where<'a, M>(
    &self,
    clause: &str,
    params: &[&dyn ToSql]
) -> Result<usize> where
    M: Model<'a>, 
[src]

Return the number of records matching a condition.

pub fn exist_where<'a, M>(
    &self,
    clause: &str,
    params: &[&dyn ToSql]
) -> Result<bool> where
    M: Model<'a>, 
[src]

Check if rows matching the given condition do exist or not.

pub fn insert_one<'a, M>(&self, entity: &M::Entity) -> Result<M::Entity> where
    M: Model<'a>, 
[src]

Insert a new entity in the database.

Returns the entity with values from database (ie: default values).

pub fn upsert_one<'a, M>(
    &self,
    entity: &M::Entity,
    target: &str,
    action: &str
) -> Result<Option<M::Entity>> where
    M: Model<'a>, 
[src]

Try to insert a new entity in the database. On constraint violation error on target you can do an alternative action action.

See ON CONFLICT clause.

Returns the entity with values from database (ie: default values).

pub fn update_one<'a, M>(
    &self,
    pk: &HashMap<&str, &dyn ToSql>,
    entity: &M::Entity
) -> Result<Option<M::Entity>> where
    M: Model<'a>, 
[src]

Update the entity.

Returns the entity with values from database.

pub fn update_by_pk<'a, M>(
    &self,
    pk: &HashMap<&str, &dyn ToSql>,
    data: &HashMap<String, &dyn ToSql>
) -> Result<Option<M::Entity>> where
    M: Model<'a>, 
[src]

Update a record and fetch it with its new values. If no records match the given key, None is returned.

pub fn delete_one<'a, M>(&self, entity: &M::Entity) -> Result<Option<M::Entity>> where
    M: Model<'a>, 
[src]

Delete an entity from a table.

Returns the entity fetched from the deleted record.

pub fn delete_by_pk<'a, M>(
    &self,
    pk: &HashMap<&str, &dyn ToSql>
) -> Result<Option<M::Entity>> where
    M: Model<'a>, 
[src]

Delete a record from its primary key. The deleted entity is returned or None if not found.

pub fn delete_where<'a, M>(
    &self,
    clause: &str,
    params: &[&dyn ToSql]
) -> Result<Rows<M::Entity>> where
    M: Model<'a>, 
[src]

Delete records by a given condition. A collection of all deleted entries is returned.

pub fn has_broken(&self) -> Result<bool>[src]

Determines if the connection is no longer usable.

pub fn notify(&self, channel: &str, data: Option<&str>) -> Result[src]

Send a NOTIFY event to the database server. An optional data can be sent with the notification.

pub fn listen(&self, channel: &str) -> Result[src]

Start to listen on the given channel.

Note: when listen is issued in a transaction it is unlisten when the transaction is committed or rollback.

pub fn unlisten(&self, channel: &str) -> Result[src]

Stop to listen on the given channel.

pub fn notifies(&self) -> Result<Option<Notify>>[src]

Check if a notification is pending. If so, the payload is returned. Otherwise, None is returned.

pub fn ping(&self) -> Result<()>[src]

Reports the status of the server.

pub fn config(&self) -> Result<Config>[src]

Retreives connection configuration.

Trait Implementations

impl Clone for Connection[src]

impl Debug for Connection[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.