---
source: tests/codegen.rs
expression: code
---
// Code generated by sqlc-gen-sqlx v[VERSION]. DO NOT EDIT.
// sqlc version: [VERSION]
#![allow(dead_code, reason = "generated queries may expose items a caller does not use")]
const DELETE_AUTHOR: &str = "DELETE FROM authors WHERE id = $1";
pub trait AsExecutor {
type Exec<'c>: sqlx::Executor<'c, Database = sqlx::Postgres> where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_>;
}
impl AsExecutor for sqlx::PgPool {
type Exec<'c> = &'c sqlx::PgPool where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_> {
&*self
}
}
impl AsExecutor for &sqlx::PgPool {
type Exec<'c> = &'c sqlx::PgPool where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_> {
*self
}
}
impl AsExecutor for sqlx::PgConnection {
type Exec<'c> = &'c mut sqlx::PgConnection where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_> {
self
}
}
impl AsExecutor for sqlx::Transaction<'_, sqlx::Postgres> {
type Exec<'c> = &'c mut sqlx::PgConnection where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_> {
&mut **self
}
}
impl AsExecutor for sqlx::pool::PoolConnection<sqlx::Postgres> {
type Exec<'c> = &'c mut sqlx::PgConnection where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_> {
&mut **self
}
}
impl<T: AsExecutor + ?Sized> AsExecutor for &mut T {
type Exec<'c> = T::Exec<'c> where Self: 'c;
fn as_executor(&mut self) -> Self::Exec<'_> {
(**self).as_executor()
}
}
pub struct Queries<E> {
db: E,
}
impl<E> Queries<E> {
pub fn new(db: E) -> Self {
Self { db }
}
pub fn into_inner(self) -> E {
self.db
}
}
impl<E: AsExecutor> Queries<E> {
pub async fn delete_author(&mut self, id: i64) -> Result<(), sqlx::Error> {
sqlx::query(DELETE_AUTHOR).bind(id).execute(self.db.as_executor()).await?;
Ok(())
}
}