Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit b6e2fa7

Browse files
tunamaguroclaude
andcommitted
docs: update CLAUDE.md with comprehensive development guidelines
Add detailed architecture documentation and development best practices including: - Expanded architecture overview with new code generation modules - Comprehensive pre-commit workflow requirements - New feature development process with planning guidelines - Updated plugin configuration options including copy_types 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9eb4d3a commit b6e2fa7

File tree

1 file changed

+90
-7
lines changed

1 file changed

+90
-7
lines changed

CLAUDE.md

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ This is `sqlc-rust-postgres`, a sqlc plugin that generates Rust code for Postgre
1212
- **Code Generation**: `src/codegen.rs` - Main code generation logic with `PostgresGenerator` struct
1313
- **Query Processing**: `src/query.rs` - Handles SQL query parsing and parameter extraction
1414
- **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
1524
- **Error Handling**: `src/error.rs` - Plugin-specific error types
1625
- **Protobuf Integration**: `src/protos/plugin/codegen.proto` - sqlc plugin protocol definitions
1726

1827
The plugin generates:
1928
- 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
2231
- Support for custom type overrides via configuration
32+
- Copy-cheap type optimizations for better performance (primitive types, database enums)
2333

2434
## Development Commands
2535

@@ -76,6 +86,7 @@ The plugin supports these configuration options in sqlc.json:
7686
- `overrides`: Custom type mappings for unsupported PostgreSQL types
7787
- `enum_derives`: Additional derive attributes for generated enums
7888
- `row_derives`: Additional derive attributes for generated row structs
89+
- `copy_types`: Additional types that should be passed by value for better performance
7990

8091
## Testing Individual Examples
8192

@@ -92,6 +103,76 @@ The plugin requires `protoc` (Protocol Buffers compiler) to be installed for bui
92103

93104
## Development Best Practices
94105

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+
95176
### Code Quality Workflow
96177
Always use `just` commands for code quality checks:
97178
- Use `just format` to format code with rustfmt before committing
@@ -115,11 +196,13 @@ When performing refactoring or making structural changes:
115196
5. Fix ALL compilation errors and lint warnings before considering the work complete
116197
6. Never leave the codebase in a broken state - compilation and tests must pass
117198

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
123206

124207
### CI/CD Integration
125208
- Always run `just format` and `just lint-fix` before pushing

0 commit comments

Comments
 (0)