Add --filter batch mode, rename binary to gormcol
This commit is contained in:
26
README.md
26
README.md
@@ -69,15 +69,19 @@ go install ./cmd/gormcol
|
||||
### Usage
|
||||
|
||||
```
|
||||
gormcol-gen [options]
|
||||
gormcol [options]
|
||||
```
|
||||
|
||||
DSN can be provided via `--dsn` flag or `DSN` env var (from `.env` file).
|
||||
|
||||
**Modes:**
|
||||
- **Interactive (default)**: select tables with fzf
|
||||
- **Batch (`--filter` or `--all`)**: generate matching tables with confirmation
|
||||
|
||||
| Flag | Default | Description |
|
||||
|----------|------------------------|--------------------------------------------------|
|
||||
| `--dsn` | *(from DSN env)* | MySQL/MariaDB DSN, e.g. `user:pass@tcp(localhost:3306)/dbname` |
|
||||
| `--filter` | `(ps_|b2b_).*` | Regex matching table names to generate |
|
||||
| `--filter` | *(interactive)* | Regex matching table names to generate (triggers batch mode) |
|
||||
| `--all` | *(interactive)* | Generate all tables matching filter (shows confirmation) |
|
||||
| `--out` | `./app/model/dbmodel` | Output directory for generated files |
|
||||
| `--pkg` | `dbmodel` | Go package name for generated files |
|
||||
@@ -87,7 +91,7 @@ DSN can be provided via `--dsn` flag or `DSN` env var (from `.env` file).
|
||||
Without flags, the tool launches an interactive table selector:
|
||||
|
||||
```bash
|
||||
gormcol-gen --dsn "user:pass@tcp(localhost:3306)/mydb"
|
||||
gormcol --dsn "user:pass@tcp(localhost:3306)/mydb"
|
||||
```
|
||||
|
||||
Features:
|
||||
@@ -96,12 +100,20 @@ Features:
|
||||
- **Enter** - confirm selection
|
||||
- **Esc** - cancel
|
||||
|
||||
### Generate All Tables
|
||||
### Batch Mode (--filter)
|
||||
|
||||
Use `--all` to generate all tables matching the filter:
|
||||
Use `--filter` to generate all tables matching a regex pattern:
|
||||
|
||||
```bash
|
||||
gormcol-gen --dsn "user:pass@tcp(localhost:3306)/mydb" --all
|
||||
gormcol --dsn "user:pass@tcp(localhost:3306)/mydb" --filter "ps_product.*"
|
||||
```
|
||||
|
||||
### Generate All Tables (--all)
|
||||
|
||||
Use `--all` to generate all tables matching the default filter `(ps_|b2b_).*`:
|
||||
|
||||
```bash
|
||||
gormcol --dsn "user:pass@tcp(localhost:3306)/mydb" --all
|
||||
```
|
||||
|
||||
A confirmation prompt appears:
|
||||
@@ -115,7 +127,7 @@ WARNING: Generate all 325 tables? [Enter] confirm / [Esc] cancel
|
||||
### Example
|
||||
|
||||
```bash
|
||||
./gormcol-gen --dsn "user:pass@tcp(localhost:3306)/mydb" --filter "ps_.*" --out ./internal/model --pkg model
|
||||
./gormcol --dsn "user:pass@tcp(localhost:3306)/mydb" --filter "ps_.*" --out ./internal/model --pkg model
|
||||
```
|
||||
|
||||
This connects to the database, generates a `.go` model file for each matching table, and appends `<Model>Cols` variables with typed `gormcol.Field` descriptors to each file.
|
||||
|
||||
Reference in New Issue
Block a user