@@ -12,14 +12,24 @@ This is `sqlc-rust-postgres`, a sqlc plugin that generates Rust code for Postgre
12
12
- ** Code Generation** : ` src/codegen.rs ` - Main code generation logic with ` PostgresGenerator ` struct
13
13
- ** Query Processing** : ` src/query.rs ` - Handles SQL query parsing and parameter extraction
14
14
- ** Type System** : ` src/user_type.rs ` - PostgreSQL to Rust type mapping with custom type overrides
15
+ - ** Database Support** : ` src/db_support/ ` - Database-specific type handling and optimizations
16
+ - ` column_types.rs ` - Column type definitions and copy-cheap type optimizations
17
+ - ` crate_types.rs ` - Database crate abstractions (tokio_postgres, postgres, deadpool_postgres)
18
+ - ** Rust Code Generation** : ` src/rust_gen/ ` - Rust-specific code generation modules
19
+ - ` const_gen.rs ` - SQL query constant generation
20
+ - ` func_gen.rs ` - Database function generation
21
+ - ` param_gen.rs ` - Function parameter generation with copy-cheap optimizations
22
+ - ` struct_gen.rs ` - Row struct generation
23
+ - ` naming.rs ` - Rust naming conventions and utilities
15
24
- ** Error Handling** : ` src/error.rs ` - Plugin-specific error types
16
25
- ** Protobuf Integration** : ` src/protos/plugin/codegen.proto ` - sqlc plugin protocol definitions
17
26
18
27
The plugin generates:
19
28
- Const strings for SQL queries
20
- - Row structs for query results
21
- - Async functions for database operations
29
+ - Row structs for query results with configurable derives
30
+ - Async functions for database operations with optimized parameter passing
22
31
- Support for custom type overrides via configuration
32
+ - Copy-cheap type optimizations for better performance (primitive types, database enums)
23
33
24
34
## Development Commands
25
35
@@ -76,6 +86,7 @@ The plugin supports these configuration options in sqlc.json:
76
86
- ` overrides ` : Custom type mappings for unsupported PostgreSQL types
77
87
- ` enum_derives ` : Additional derive attributes for generated enums
78
88
- ` row_derives ` : Additional derive attributes for generated row structs
89
+ - ` copy_types ` : Additional types that should be passed by value for better performance
79
90
80
91
## Testing Individual Examples
81
92
@@ -92,6 +103,76 @@ The plugin requires `protoc` (Protocol Buffers compiler) to be installed for bui
92
103
93
104
## Development Best Practices
94
105
106
+ ### Branch Management and Pre-Commit Workflow
107
+ ** ALWAYS** create a feature branch before starting work:
108
+ ``` bash
109
+ git checkout -b feature/your-feature-name
110
+ ```
111
+
112
+ ** MANDATORY** checks before every commit:
113
+ 1 . ** Format** : ` just format ` - Ensure code is properly formatted
114
+ 2 . ** Lint** : ` just lint-fix ` - Fix all clippy warnings and errors
115
+ 3 . ** Compile** : Verify no compilation errors exist
116
+ 4 . ** Test** : ` just test ` - Ensure all tests pass
117
+
118
+ ** NEVER** commit code that fails any of the above checks. The codebase must always remain in a working state.
119
+
120
+ ### New Feature Development Process
121
+
122
+ #### Requirements Analysis and Planning
123
+ ** Before implementing, always execute the following:**
124
+
125
+ 1 . ** Root Cause Analysis**
126
+ - Identify not just the immediate problem (e.g., ` id: &i64 ` ) but all related issues
127
+ - Consider similar cases (enums, user-defined types, etc.) simultaneously
128
+ - Map out the complete problem domain
129
+
130
+ 2 . ** Define Expected Completion State**
131
+ ``` rust
132
+ // Before: get_author(client, &123, &Status::Open)
133
+ // After: get_author(client, 123, Status::Open)
134
+ ```
135
+
136
+ 3 . ** Identify Technical Constraints**
137
+ - Future extensibility requirements
138
+ - Performance requirements (static vs dynamic dispatch)
139
+ - Backward compatibility with existing APIs
140
+
141
+ 4 . ** Design Comprehensive Solution**
142
+ - Avoid piecemeal fixes; design to solve the entire problem domain
143
+ - Balance configurability with automation
144
+ - Consider the impact on the entire system
145
+
146
+ #### Implementation Process
147
+
148
+ 1 . ** Use Plan Mode for Complex Features**
149
+ - Always present overall design in plan mode for complex features
150
+ - Define specific phases with clear completion criteria
151
+ - Identify dependencies and potential roadblocks upfront
152
+
153
+ 2 . ** Staged but Consistent Implementation**
154
+ - Each stage should maintain a working state
155
+ - Design comprehensively upfront to avoid rework
156
+ - Commit at meaningful milestones (not arbitrary stopping points)
157
+
158
+ 3 . ** Validation and Feedback**
159
+ - Verify functionality at each stage
160
+ - Test with real use cases
161
+ - Incorporate feedback early and often
162
+
163
+ #### Anti-Patterns to Avoid
164
+
165
+ - ** Reactive Implementation** : Solving only the immediate symptom
166
+ - ** Late Requirements** : Discovering requirements during implementation
167
+ - ** Technical Debt** : Leaving inefficient implementations (e.g., dynamic dispatch)
168
+ - ** Scope Creep** : Adding unrelated features during implementation
169
+
170
+ #### Success Patterns
171
+
172
+ - ** Proactive Design** : Identify all related problems before coding
173
+ - ** Comprehensive Solutions** : Design to solve the entire problem domain
174
+ - ** Staged Implementation** : Comprehensive design, incremental execution
175
+
95
176
### Code Quality Workflow
96
177
Always use ` just ` commands for code quality checks:
97
178
- Use ` just format ` to format code with rustfmt before committing
@@ -115,11 +196,13 @@ When performing refactoring or making structural changes:
115
196
5 . Fix ALL compilation errors and lint warnings before considering the work complete
116
197
6 . Never leave the codebase in a broken state - compilation and tests must pass
117
198
118
- ### Testing Error Scenarios
119
- - Create temporary test configurations in ` test_error/ ` directory
120
- - Use ` _test_error_sqlc.json ` with dynamic WASM SHA256 replacement
121
- - Build WASM plugin with ` just build-wasm-dev ` before testing
122
- - Generate dynamic config: ` WASM_SHA256=$(sha256sum target/wasm32-wasip1/debug/sqlc-rust-postgres.wasm | awk '{print $1}'); sed "s/\$WASM_SHA256/${WASM_SHA256}/g" config_template.json > actual_config.json `
199
+ ### Pull Request Workflow
200
+ Before creating a PR:
201
+ 1 . ** Branch** : Work on a feature branch (never directly on main)
202
+ 2 . ** Quality** : Run the mandatory pre-commit checks (format, lint, compile, test)
203
+ 3 . ** Generate** : Run ` just generate ` to ensure WASM builds and code generation works
204
+ 4 . ** Push** : Push the feature branch to remote
205
+ 5 . ** PR** : Create PR with descriptive title and comprehensive description
123
206
124
207
### CI/CD Integration
125
208
- Always run ` just format ` and ` just lint-fix ` before pushing
0 commit comments