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: &str = "SELECT id, name, bio FROM authors WHERE id = $1";
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct GetAuthorRow {
    pub id: i64,
    pub name: String,
    pub bio: Option<String>,
}
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(&mut self, id: i64) -> Result<GetAuthorRow, sqlx::Error> {
        sqlx::query_as::<_, GetAuthorRow>(GET_AUTHOR)
            .bind(id)
            .fetch_one(&mut self.db)
            .await
    }
}