pq2gorm

command module
v0.0.0-...-f94869b Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2018 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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/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

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
⌂ 换网址