First working version
This commit is contained in:
136
README.md
Normal file
136
README.md
Normal file
@ -0,0 +1,136 @@
|
||||
# Entity Maker
|
||||
|
||||
A command-line tool for generating SQLAlchemy entities from PostgreSQL database tables.
|
||||
|
||||
## Features
|
||||
|
||||
- Connects to PostgreSQL database and introspects table structure
|
||||
- Generates Python 3.13 code using SQLAlchemy
|
||||
- Creates complete entity scaffolding including:
|
||||
- SQLAlchemy table definition
|
||||
- Dataclass model
|
||||
- Filter class
|
||||
- Load options
|
||||
- Repository
|
||||
- Manager
|
||||
- Factory (for testing)
|
||||
- Mapper
|
||||
- Enum types (if table uses PostgreSQL enums)
|
||||
|
||||
## Installation
|
||||
|
||||
### Build from source
|
||||
|
||||
```bash
|
||||
go build -o entity-maker ./cmd/entity-maker
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Interactive Mode
|
||||
|
||||
Run the application without arguments to use interactive prompts:
|
||||
|
||||
```bash
|
||||
./entity-maker
|
||||
```
|
||||
|
||||
The application will prompt you for:
|
||||
- Database host (default: localhost)
|
||||
- Database port (default: 5432)
|
||||
- Database name (required)
|
||||
- Database schema (default: public)
|
||||
- Database user (default: postgres)
|
||||
- Database password (default: postgres)
|
||||
- Table name (required)
|
||||
- Output directory (required)
|
||||
- Entity name override (optional)
|
||||
|
||||
### Command-Line Arguments
|
||||
|
||||
You can also provide parameters via command-line flags:
|
||||
|
||||
```bash
|
||||
./entity-maker \
|
||||
-host localhost \
|
||||
-port 5432 \
|
||||
-db mydb \
|
||||
-schema public \
|
||||
-user postgres \
|
||||
-password secret \
|
||||
-table users \
|
||||
-output ./output \
|
||||
-entity User
|
||||
```
|
||||
|
||||
### Available Flags
|
||||
|
||||
- `-host` - Database host
|
||||
- `-port` - Database port
|
||||
- `-db` - Database name
|
||||
- `-schema` - Database schema
|
||||
- `-user` - Database user
|
||||
- `-password` - Database password
|
||||
- `-table` - Table name to generate entities from
|
||||
- `-output` - Output directory path
|
||||
- `-entity` - Entity name override (optional, defaults to singularized table name)
|
||||
|
||||
## Configuration
|
||||
|
||||
The application saves your settings to `~/.config/entity-maker.toml` for future use. When you run the application again, it will use these saved values as defaults.
|
||||
|
||||
## Generated Files
|
||||
|
||||
For a table named `users`, the following files will be generated in `output/user/`:
|
||||
|
||||
- `table.py` - SQLAlchemy Table definition
|
||||
- `model.py` - Dataclass model with type hints
|
||||
- `filter.py` - Filter class for queries
|
||||
- `load_options.py` - Relationship loading options
|
||||
- `repository.py` - CRUD repository
|
||||
- `manager.py` - Manager class
|
||||
- `factory.py` - Factory for testing (uses factory_boy)
|
||||
- `mapper.py` - SQLAlchemy mapper configuration
|
||||
- `enum.py` - Enum types (only if table uses PostgreSQL enums)
|
||||
- `__init__.py` - Package initialization
|
||||
|
||||
## Example
|
||||
|
||||
Generate entities for the `cashbag_conforms` table:
|
||||
|
||||
```bash
|
||||
./entity-maker -db mydb -table cashbag_conforms -output ./output
|
||||
```
|
||||
|
||||
This will create files in `./output/cashbag_conform/`:
|
||||
- Entity name: `CashbagConform`
|
||||
- Module name: `cashbag_conform`
|
||||
- All supporting files
|
||||
|
||||
## Requirements
|
||||
|
||||
- PostgreSQL database
|
||||
- Go 1.21+ (for building)
|
||||
- Python 3.13+ (for generated code)
|
||||
- SQLAlchemy (for generated code)
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
entity-maker/
|
||||
├── cmd/
|
||||
│ └── entity-maker/ # Main application
|
||||
├── internal/
|
||||
│ ├── config/ # Configuration management
|
||||
│ ├── database/ # Database connection and introspection
|
||||
│ ├── generator/ # Code generators
|
||||
│ ├── naming/ # Naming utilities (pluralization, case conversion)
|
||||
│ └── prompt/ # Interactive CLI prompts
|
||||
├── example/ # Example output files
|
||||
├── CLAUDE.md # Detailed specification
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
See LICENSE file for details.
|
||||
Reference in New Issue
Block a user