sqlc-gen-sqlx 0.1.0

A sqlc plugin that generates type-safe sqlx Rust code from SQL queries.
Documentation
---
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 GET_AUTHOR_EMBED: &str = "SELECT a.id, a.name, a.bio FROM authors a WHERE a.id = $1";
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct AuthorsEmbed {
    pub id: i64,
    pub name: String,
    pub bio: Option<String>,
}
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct GetAuthorEmbedRow {
    #[sqlx(flatten)]
    pub authors: AuthorsEmbed,
}
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 get_author_embed(
        &mut self,
        id: i64,
    ) -> Result<GetAuthorEmbedRow, sqlx::Error> {
        sqlx::query_as::<_, GetAuthorEmbedRow>(GET_AUTHOR_EMBED)
            .bind(id)
            .fetch_one(&mut self.db)
            .await
    }
}