---
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")]
#[derive(Debug, Clone)]
pub struct CopyAuthorsParams {
pub name: String,
pub bio: Option<String>,
}
const COPY_AUTHORS: &str = "INSERT INTO authors (name, bio) ";
const COPY_AUTHORS_BATCH_SIZE: usize = 32767usize;
pub struct Queries<E> {
db: E,
}
impl<E> Queries<E> {
pub fn new(db: E) -> Self {
Self { db }
}
}
impl<E> Queries<E>
where
for<'c> &'c mut E: sqlx::Executor<'c, Database = sqlx::Postgres>,
{
pub async fn copy_authors<I>(&mut self, items: I) -> Result<u64, sqlx::Error>
where
I: IntoIterator<Item = CopyAuthorsParams>,
{
let mut rows_affected = 0u64;
let mut items = items.into_iter();
loop {
let chunk = items.by_ref().take(COPY_AUTHORS_BATCH_SIZE).collect::<Vec<_>>();
if chunk.is_empty() {
break;
}
let mut query_builder = sqlx::QueryBuilder::<
sqlx::Postgres,
>::new(COPY_AUTHORS);
query_builder
.push_values(
chunk,
|mut b, item| {
b.push_bind(item.name);
b.push_bind(item.bio);
},
);
rows_affected
+= query_builder.build().execute(&mut self.db).await?.rows_affected();
}
Ok(rows_affected)
}
}