wantedly/pq2gorm

Name: pq2gorm

Owner: Wantedly, Inc.

Description: Generate gorm model structs from PostgreSQL database schema

Created: 2016-08-29 10:47:02.0

Updated: 2018-05-05 08:23:14.0

Pushed: 2016-09-27 05:46:57.0

Homepage: null

Size: 73

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

pq2gorm - Generate gorm model structs from PostgreSQL database schema

Build Status

pq2gorm is a generator of gorm model structs from a PostgresSQL database.

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

 get -d -u github.com/wantedly/pq2gorm
 $GOPATH/src/github.com/wantedly/pq2gorm
ke
ke 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
2gorm
e: Generate gorm model structs from PostgreSQL database schema.
 string
    Set output path (default "./")
ir string
    Set output path (default "./")
 string
    Target tables (table1,table2,...) (default: all tables)
ables string
    Target tables (table1,table2,...) (default: all tables)

Example 1: Generate gorm model files of all tables in current directory.

2gorm "postgresql://user:password@host:port/dbname?sslmode=disable"

For example, user model user.go as shown below will be generated:

 User struct {
ID uint `json:"id"`
...

Example 2: Generate gorm model files of all tables in ./out directory.

2gorm "postgresql://user:password@host:port/dbname?sslmode=disable" -d ./out

Example 3: Generate gorm model files of profiles and users tables.

2gorm "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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.