---
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 LIST_AUTHORS_BY_DYNAMIC_IDS: &str = "SELECT id, name, bio FROM authors WHERE id IN ($1)";
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct ListAuthorsByDynamicIdsRow {
pub id: i64,
pub name: String,
pub bio: Option<String>,
}
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 list_authors_by_dynamic_ids(
&mut self,
ids: Vec<i64>,
) -> Result<Vec<ListAuthorsByDynamicIdsRow>, sqlx::Error> {
let mut sql = LIST_AUTHORS_BY_DYNAMIC_IDS.to_string();
let mut next_placeholder = 1usize;
let placeholder_1 = next_placeholder;
let slice_len = (ids).len();
let replacement = if slice_len == 0 {
"NULL".to_string()
} else {
(placeholder_1..(placeholder_1 + slice_len))
.map(|n| format!("${}", n))
.collect::<Vec<_>>()
.join(", ")
};
if sql.contains("/*SLICE:ids*/?") {
sql = sql.replace("/*SLICE:ids*/?", &replacement);
} else {
if sql.contains("/*SLICE:ids*/$1") {
sql = sql.replace("/*SLICE:ids*/$1", &replacement);
} else {
sql = sql.replace("$1", &replacement);
}
}
next_placeholder += slice_len;
let mut query = sqlx::query_as::<_, ListAuthorsByDynamicIdsRow>(&sql);
for value in ids {
query = query.bind(value);
}
query.fetch_all(self.db.as_executor()).await
}
}