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 CREATE_AUTHOR: &str = "INSERT INTO authors (name) VALUES ($1) RETURNING id";
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 create_author(&mut self, name: String) -> Result<i64, sqlx::Error> {
        let (_row,): (i64,) = sqlx::query_as(CREATE_AUTHOR)
            .bind(name)
            .fetch_one(&mut self.db)
            .await?;
        Ok(_row)
    }
}