Struct elephantry::Pool [−][src]
Connections pool.
Implementations
impl Pool
[src]
pub fn new(url: &str) -> Result<Self>
[src]
Create a new pool with a default connection.
pub fn from_config(config: &Config) -> Result<Self>
[src]
Create a new pool with a default connection from Config
.
pub fn add_default(self, name: &str, url: &str) -> Result<Self>
[src]
Add a default connection.
pub fn add_connection(self, name: &str, url: &str) -> Result<Self>
[src]
Add a connection.
pub fn get_default(&self) -> Option<&Connection>
[src]
Retreive the default connection.
pub fn set_default(&mut self, name: &str) -> Result<()>
[src]
Set the connection name
as default.
pub fn get(&self, name: &str) -> Option<&Connection>
[src]
Retreive the connection name
, on None
if not exists.
pub fn remove(&mut self, name: &str)
[src]
Remove the connection name
.
Methods from Deref<Target = Connection>
pub fn async(&self) -> Async<'_>ⓘ
[src]
pub fn transaction(&self) -> Transaction<'_>
[src]
pub fn model<'a, M>(&'a self) -> M where
M: Model<'a>,
[src]
M: Model<'a>,
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]
&self,
query: &str,
params: &[&dyn ToSql]
) -> Result<Rows<E>>
Executes a simple query, can have parameters.
pub fn query_one<E: Entity>(
&self,
query: &str,
params: &[&dyn ToSql]
) -> Result<E>
[src]
&self,
query: &str,
params: &[&dyn ToSql]
) -> Result<E>
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]
&self,
pk: &HashMap<&str, &dyn ToSql>
) -> Result<Option<M::Entity>> where
M: Model<'a>,
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]
M: Model<'a>,
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]
&self,
clause: &str,
params: &[&dyn ToSql],
suffix: Option<&str>
) -> Result<Rows<M::Entity>> where
M: Model<'a>,
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]
&self,
clause: &str,
params: &[&dyn ToSql],
max_per_page: usize,
page: usize,
suffix: Option<&str>
) -> Result<Pager<M::Entity>> where
M: Model<'a>,
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]
&self,
clause: &str,
params: &[&dyn ToSql]
) -> Result<usize> where
M: Model<'a>,
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]
&self,
clause: &str,
params: &[&dyn ToSql]
) -> Result<bool> where
M: Model<'a>,
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]
M: Model<'a>,
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]
&self,
entity: &M::Entity,
target: &str,
action: &str
) -> Result<Option<M::Entity>> where
M: Model<'a>,
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]
&self,
pk: &HashMap<&str, &dyn ToSql>,
entity: &M::Entity
) -> Result<Option<M::Entity>> where
M: Model<'a>,
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]
&self,
pk: &HashMap<&str, &dyn ToSql>,
data: &HashMap<String, &dyn ToSql>
) -> Result<Option<M::Entity>> where
M: Model<'a>,
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]
M: Model<'a>,
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]
&self,
pk: &HashMap<&str, &dyn ToSql>
) -> Result<Option<M::Entity>> where
M: Model<'a>,
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]
&self,
clause: &str,
params: &[&dyn ToSql]
) -> Result<Rows<M::Entity>> where
M: Model<'a>,
Delete records by a given condition. A collection of all deleted entries is returned.
pub fn has_broken(&self) -> 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) -> Option<Notify>
[src]
Check if a notification is pending. If so, the payload is returned.
Otherwise, None
is returned.
Trait Implementations
impl Clone for Pool
[src]
impl Debug for Pool
[src]
impl Default for Pool
[src]
impl Deref for Pool
[src]
type Target = Connection
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl Index<&'_ str> for Pool
[src]
Auto Trait Implementations
impl RefUnwindSafe for Pool
[src]
impl Send for Pool
[src]
impl Sync for Pool
[src]
impl Unpin for Pool
[src]
impl UnwindSafe for Pool
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,