Skip to content

Commit 50b19ad

Browse files
committed
Added more integration tests
1 parent 9f71782 commit 50b19ad

3 files changed

Lines changed: 446 additions & 608 deletions

File tree

store/README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ go install gofr.dev/cli/gofr@latest
2020
```
2121
This creates:
2222
- `stores/store.yaml` — central configuration template
23+
- `stores/all.go` — store registry factory (auto-generated)
2324
- `stores/user/interface.go` — initial interface stub
24-
- `stores/user/user.go` — initial implementation stub
25+
- `stores/user/user.go` — initial implementation stub (editable)
2526

2627
2. **Edit `stores/store.yaml`** with your models and queries (see Configuration Reference below).
2728

@@ -57,16 +58,27 @@ gofr store generate -config=custom-store.yaml
5758

5859
### Project Structure
5960

60-
After generation, your project will have:
61+
**After `gofr store init -name=user`:**
6162

6263
```
6364
stores/
64-
├── store.yaml # Central configuration
65-
├── all.go # Store registry factory (auto-generated)
65+
├── store.yaml # Central configuration template (edit this)
66+
├── all.go # Store registry factory (auto-generated, DO NOT EDIT)
6667
└── user/
67-
├── interface.go # UserStore interface
68-
├── userStore.go # userStore implementation boilerplate
69-
└── user.go # User model (if generated)
68+
├── interface.go # UserStore interface stub (DO NOT EDIT — regenerated by generate)
69+
└── user.go # userStore implementation stub (editable — add your SQL logic here)
70+
```
71+
72+
**After `gofr store generate`:**
73+
74+
```
75+
stores/
76+
├── store.yaml # Central configuration (source of truth)
77+
├── all.go # Store registry factory (DO NOT EDIT)
78+
└── user/
79+
├── interface.go # UserStore interface (DO NOT EDIT — regenerated each time)
80+
├── userStore.go # userStore implementation boilerplate (add SQL logic here)
81+
└── user.go # User model (if defined in YAML, DO NOT EDIT)
7082
```
7183

7284
### Using Generated Stores
@@ -162,7 +174,7 @@ models:
162174
| `output_dir` | Directory for generated files | Optional (defaults to `stores/<name>`) |
163175
| `interface` | Interface name — **recommended: `<Name>Store`** (e.g., `UserStore`) | Optional (defaults to `<Name>Store`) |
164176
| `implementation` | Implementation struct name (e.g., `userStore`) | Optional (defaults to `<name>Store`) |
165-
| `queries` | Array of database queries | **Yes** |
177+
| `queries` | Array of database queries | Optional |
166178

167179
> **⚠️ Naming Convention:** The registry (`stores/all.go`) automatically appends `"Store"` when building constructor calls. To avoid compilation errors, always name your interface as `<Name>Store` (e.g., `UserStore`) and the generated constructor will be `New<Name>Store()`.
168180

@@ -309,7 +321,7 @@ func (User) TableName() string {
309321

310322
## Best Practices
311323

312-
1. **Never Edit Generated Files**: Files marked `DO NOT EDIT` (`interface.go`, `all.go`) are overwritten on every generation. Keep custom SQL logic in your implementation file (e.g., `userStore.go`).
324+
1. **Know Which Files Are Auto-Generated**: Only `interface.go` and `all.go` are marked `DO NOT EDIT` and are overwritten on every `gofr store generate`. The implementation stub (`<name>.go` or `<name>Store.go`) created by `gofr store init` is editable — this is where you add your SQL logic.
313325
2. **Use `<Name>Store` Interface Names**: This ensures the registry and constructor align correctly.
314326
3. **Commit your YAML**: Treat `store.yaml` as source of truth. Re-run `gofr store generate` after every change.
315327
4. **Reference Existing Models**: If you already have model structs, use the `path` + `package` fields to avoid duplication.

0 commit comments

Comments
 (0)