Files
rust-lib/crates/diesel_crud_derive/src/list.rs

23 lines
680 B
Rust
Raw Normal View History

use crate::{Attributes, common};
2024-08-19 19:40:14 +02:00
use quote::quote;
pub(crate) fn derive_diesel_crud_list_impl(
Attributes {
struct_ident,
table,
..
}: &Attributes,
2024-08-19 19:40:14 +02:00
) -> proc_macro2::TokenStream {
let return_type = common::return_type(quote! { Vec<Self> });
2024-08-19 19:40:14 +02:00
quote! {
#[automatically_derived]
impl lib::diesel_crud_trait::DieselCrudList for #struct_ident {
async fn list(conn: &mut diesel_async::AsyncPgConnection) -> #return_type {
use diesel::associations::HasTable;
diesel_async::RunQueryDsl::get_results(#table::table::table(), conn).await.map_err(Into::into)
2024-08-19 19:40:14 +02:00
}
}
}
}