mod bulk;
mod constraints;
mod context;
mod crud;
mod domain_ops;
mod lookup;
mod notify;
mod outbox;
mod projections;
mod query;
mod relations;
mod save;
mod scoped;
mod scopes;
mod soft_delete;
mod upsert;
pub mod helpers;
pub use context::Context;
use proc_macro2::TokenStream;
use quote::quote;
use crate::{entity::parse::EntityDef, utils::marker};
pub fn generate(entity: &EntityDef) -> TokenStream {
if !cfg!(feature = "postgres") {
return TokenStream::new();
}
let ctx = Context::new(entity);
let trait_name = &ctx.trait_name;
let error_type = entity.error_type();
let create_impl = ctx.create_method();
let upsert_impl = ctx.upsert_method();
let find_impl = ctx.find_by_id_method();
let update_impl = ctx.update_method();
let delete_impl = ctx.delete_method();
let list_impl = ctx.list_method();
let list_after_impl = ctx.list_after_method();
let find_by_ids_impl = ctx.find_by_ids_method();
let create_many_impl = ctx.create_many_method();
let delete_many_impl = ctx.delete_many_method();
let query_impl = ctx.query_method();
let stream_impl = ctx.stream_filtered_method();
let relation_impls = ctx.relation_methods();
let projection_impls = ctx.projection_methods();
let soft_delete_impls = ctx.soft_delete_methods();
let scoped_impls = ctx.scoped_methods();
let participant_scope_impls = ctx.scope_methods();
let domain_operation_impls = ctx.domain_operation_methods();
let lookup_impls = ctx.lookup_methods();
let save_impl = ctx.save_method();
let constraint_mapper = ctx.constraint_mapper();
let marker = marker::generated();
quote! {
#marker
#constraint_mapper
#[::entity_derive::async_trait]
impl #trait_name for sqlx::PgPool {
type Error = #error_type;
type Pool = sqlx::PgPool;
fn pool(&self) -> &Self::Pool {
self
}
#create_impl
#upsert_impl
#find_impl
#update_impl
#delete_impl
#list_impl
#list_after_impl
#find_by_ids_impl
#create_many_impl
#delete_many_impl
#query_impl
#stream_impl
#lookup_impls
#relation_impls
#projection_impls
#soft_delete_impls
#scoped_impls
#participant_scope_impls
#domain_operation_impls
#save_impl
}
}
}