https://github.com/pengux/cruder
Generate code for CRUD functions from a Go struct
https://github.com/pengux/cruder
code-generation crud-functionality golang
Last synced: about 1 month ago
JSON representation
Generate code for CRUD functions from a Go struct
- Host: GitHub
- URL: https://github.com/pengux/cruder
- Owner: pengux
- License: gpl-3.0
- Created: 2017-02-27T11:18:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-12T12:31:51.000Z (almost 7 years ago)
- Last Synced: 2025-03-31T07:11:11.116Z (3 months ago)
- Topics: code-generation, crud-functionality, golang
- Language: Go
- Size: 43 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cruder
Generate code for CRUD functions from a Go struct[](https://goreportcard.com/report/github.com/pengux/cruder)
## Usage
```
cruder is a tool to generate code for Create, Read, Update, Delete functions
from a Go struct. It supports multiple generators which currently are:Functions that can be generated are:
- Create: Adds an entry
- Read: Gets an entry using an ID
- List: Gets multiple entries
- Update: Updates an entry
- Delete: Deletes an entry using an IDUsage:
cruder [command]Available Commands:
help Help about any command
pg Generates CRUD methods for Postgresql, uses the lib/pg packageFlags:
--fn stringArray CRUD functions to generate, e.g. --fn "create" --fn "delete". Default to all functions (default [create,get,list,update,delete])
-h, --help help for cruder
--pkg string package name for the generated code, default to the same package from input
--primaryfield string the field to use as primary key. Default to 'ID' if it exists in the
--readfield stringArray Fields in the struct that should be used for read operations (get,list). Default to all fields except the one used for softdelete
--skipsuffix Skip adding the struct name as suffix to the generated functions
--softdeletefield string the field to use for softdelete (should be of type nullable datetime field). Default to 'DeletedAt' if it exists in the
--writefield stringArray Fields in the struct that should be used for write operations (create,update). Default to all fieldsUse "cruder [command] --help" for more information about a command.
```### Example
```sh
cruder --table=foos Foo example/example.go
```