Foreign keys were not being pulled properly
- Fix many comments.
This commit is contained in:
parent
fc4efc782d
commit
a722998d40
1 changed files with 7 additions and 4 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
// Side-effect import sql driver
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ func (p *PostgresDriver) Close() {
|
||||||
p.dbConn.Close()
|
p.dbConn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// tableNames connects to the postgres database and
|
// TableNames connects to the postgres database and
|
||||||
// retrieves all table names from the information_schema where the
|
// retrieves all table names from the information_schema where the
|
||||||
// table schema is public. It excludes common migration tool tables
|
// table schema is public. It excludes common migration tool tables
|
||||||
// such as gorp_migrations
|
// such as gorp_migrations
|
||||||
|
@ -71,7 +72,7 @@ func (p *PostgresDriver) TableNames() ([]string, error) {
|
||||||
return names, nil
|
return names, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// columns takes a table name and attempts to retrieve the table information
|
// Columns takes a table name and attempts to retrieve the table information
|
||||||
// from the database information_schema.columns. It retrieves the column names
|
// from the database information_schema.columns. It retrieves the column names
|
||||||
// and column types and returns those as a []Column after TranslateColumnType()
|
// and column types and returns those as a []Column after TranslateColumnType()
|
||||||
// converts the SQL types to Go types, for example: "varchar" to "string"
|
// converts the SQL types to Go types, for example: "varchar" to "string"
|
||||||
|
@ -113,7 +114,7 @@ func (p *PostgresDriver) Columns(tableName string) ([]Column, error) {
|
||||||
return columns, nil
|
return columns, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// primaryKeyInfo looks up the primary key for a table.
|
// PrimaryKeyInfo looks up the primary key for a table.
|
||||||
func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
|
func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
|
||||||
pkey := &PrimaryKey{}
|
pkey := &PrimaryKey{}
|
||||||
var err error
|
var err error
|
||||||
|
@ -162,7 +163,7 @@ func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) {
|
||||||
return pkey, nil
|
return pkey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// foreignKeyInfo retrieves the foreign keys for a given table name.
|
// ForeignKeyInfo retrieves the foreign keys for a given table name.
|
||||||
func (p *PostgresDriver) ForeignKeyInfo(tableName string) ([]ForeignKey, error) {
|
func (p *PostgresDriver) ForeignKeyInfo(tableName string) ([]ForeignKey, error) {
|
||||||
var fkeys []ForeignKey
|
var fkeys []ForeignKey
|
||||||
|
|
||||||
|
@ -192,6 +193,8 @@ func (p *PostgresDriver) ForeignKeyInfo(tableName string) ([]ForeignKey, error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fkeys = append(fkeys, fkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue