pq2gorm

command module
v0.0.0-...-324ffe8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 15 Imported by: 0

README

pq2gorm - Generate gorm model structs from PostgreSQL database schema

Build Status

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/fahmifan/pq2gorm
$ cd $GOPATH/src/github.com/fahmifan/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"  -dbtype postgres -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

Example 4 Generate gorm model files of all tables in ./out directory for cockroachdb.

$ pq2gorm "postgresql://user:password@host:port/dbname?sslmode=disable"  -dbtype cockroachdb -dbname $dbname -d ./out

If the directory ./out does not exist, pq2gorm creates ./out directory with output files.

License

MIT License

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL