pq2gorm - Generate gorm model structs from PostgreSQL database schema
pq2gorm is a generator of gorm model structs from a PostgresSQL database.
- Input: Connection URI of a PostgresSQL database.
- Output: Model definitions based on gorm annotated struct.
How to build and install
Prepare Go 1.6 or higher.
Go 1.5 is acceptable, but GO15VENDOREXPERIMENT=1
must be set.
After installing required version of Go, you can build and install pq2gorm
by
$ go get -d -u github.com/bitgaming/pq2gorm
$ cd $GOPATH/src/github.com/bitgaming/pq2gorm
$ make
$ make install
make
generates a binary into bin/pq2gorm
.
make install
put it to $GOPATH/bin
.
How to use
Run pq2gorm
with Connection URI of a PostgresSQL database.
Connection URI is necessary for running.
Usage
$ pq2gorm
Usage: Generate gorm model structs from PostgreSQL database schema.
-d string
Set output path (default "./")
-dir string
Set output path (default "./")
-t string
Target tables (table1,table2,...) (default: all tables)
-tables string
Target tables (table1,table2,...) (default: all tables)
Example 1: Generate gorm model files of all tables in current directory.
$ pq2gorm "postgresql://user:password@host:port/dbname?sslmode=disable"
For example, user model user.go as shown below will be generated:
type User struct {
ID uint `json:"id"`
...
}
Example 2: Generate gorm model files of all tables in ./out
directory.
$ pq2gorm "postgresql://user:password@host:port/dbname?sslmode=disable" -d ./out
Example 3: Generate gorm model files of profiles
and users
tables.
$ pq2gorm "postgresql://user:password@host:port/dbname?sslmode=disable" -d ./out -t profiles,users
If the directory ./out
does not exist, pq2gorm
creates ./out
directory with output files.
License