1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-FileCopyrightText: 2025-2026 RAprogramm <andrey.rozanov.vl@gmail.com>
// SPDX-License-Identifier: MIT
//! PostgreSQL repository implementation generator.
//!
//! Generates `impl {Name}Repository for sqlx::PgPool` with complete CRUD
//! operations. This is the primary database backend, providing full SQL support
//! via sqlx.
//!
//! # Module Structure
//!
//! ```text
//! postgres/
//! ├── mod.rs — Main generator and public API
//! ├── context.rs — Generation context with precomputed values
//! ├── crud.rs — CREATE, READ, UPDATE, DELETE, LIST methods
//! ├── query.rs — Type-safe query filtering method
//! ├── relations.rs — belongs_to and has_many relation methods
//! ├── projections.rs — Optimized projection SELECT methods
//! ├── soft_delete.rs — Soft delete support methods
//! └── helpers.rs — SQL building helper functions
//! ```
//!
//! # Generated Implementation
//!
//! ```rust,ignore
//! #[cfg(feature = "postgres")]
//! #[async_trait]
//! impl UserRepository for sqlx::PgPool {
//! type Error = sqlx::Error;
//! type Pool = sqlx::PgPool;
//!
//! fn pool(&self) -> &Self::Pool { self }
//!
//! // CRUD methods
//! async fn create(&self, dto: CreateUserRequest) -> Result<User, Self::Error>;
//! async fn find_by_id(&self, id: Uuid) -> Result<Option<User>, Self::Error>;
//! async fn update(&self, id: Uuid, dto: UpdateUserRequest) -> Result<User, Self::Error>;
//! async fn delete(&self, id: Uuid) -> Result<bool, Self::Error>;
//! async fn list(&self, limit: i64, offset: i64) -> Result<Vec<User>, Self::Error>;
//!
//! // Query method (if #[filter] used)
//! async fn query(&self, query: UserQuery) -> Result<Vec<User>, Self::Error>;
//!
//! // Relation methods
//! async fn find_organization(&self, id: Uuid) -> Result<Option<Organization>, Self::Error>;
//! async fn find_posts(&self, user_id: Uuid) -> Result<Vec<Post>, Self::Error>;
//!
//! // Projection methods
//! async fn find_by_id_public(&self, id: Uuid) -> Result<Option<UserPublic>, Self::Error>;
//!
//! // Soft delete methods (if soft_delete enabled)
//! async fn hard_delete(&self, id: Uuid) -> Result<bool, Self::Error>;
//! async fn restore(&self, id: Uuid) -> Result<bool, Self::Error>;
//! }
//! ```
//!
//! # Feature Flag
//!
//! Generated code is gated behind `#[cfg(feature = "postgres")]`.
pub use Context;
use TokenStream;
use quote;
use crate::;
/// Generate PostgreSQL repository implementation.
///
/// Creates `impl {Name}Repository for sqlx::PgPool` with all CRUD methods,
/// relation methods, projection methods, query method, and soft delete methods.
///
/// # Generated Methods
///
/// | Category | Methods |
/// |----------|---------|
/// | CRUD | `create`, `find_by_id`, `update`, `delete`, `list` |
/// | Query | `query` (if entity has `#[filter]` fields) |
/// | Relations | `find_{parent}`, `find_{children}` |
/// | Projections | `find_by_id_{projection}` |
/// | Soft Delete | `hard_delete`, `restore`, `*_with_deleted` |