[−][src]Struct elephantry::Connection
A connection to a database.
Implementations
impl Connection
[src]
pub fn new(dsn: &str) -> Result<Self>
[src]
pub fn async(&self) -> Async<'_>ⓘ
[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]
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 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 notifies(&self) -> Option<Notify>
[src]
Check if a notification is pending. If so, the payload is returned.
Otherwise, None
is returned.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
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, 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>,