schemareader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadTableNames = `SELECT table_name
		FROM information_schema.tables
		WHERE table_schema = 'public'
			AND table_type = 'BASE TABLE';`

	ReadColumnNames = `` /* 133-byte string literal not displayed */

	ReadPkColumnNames = `` /* 175-byte string literal not displayed */

	ReadUniqueIndexNames = `` /* 213-byte string literal not displayed */

	ReadIndexColumns = `` /* 169-byte string literal not displayed */

	ReadReferenceConstraintNames = `` /* 296-byte string literal not displayed */

	ReadReferencedByConstraintNames = `` /* 297-byte string literal not displayed */

	ReadReferencedTable = `SELECT DISTINCT ccu.table_name
	FROM information_schema.constraint_column_usage AS ccu
	WHERE ccu.constraint_name = $1;`

	ReadReferencedByTable = `SELECT DISTINCT table_name
	FROM information_schema.table_constraints as tc 
	WHERE tc.constraint_name = $1;`

	ReadReferenceConstraints = `` /* 539-byte string literal not displayed */

	ReadPkSequence = `` /* 754-byte string literal not displayed */

)
View Source
const (
	VirtualIndexName = "virtual_main_unique_index"
)

Variables

This section is empty.

Functions

func DumpToGraphviz

func DumpToGraphviz(tables map[string]Table)

DumpToGraphviz outputs a dot representation of a schema. Use: go run . | dot -Tx11

func GetConnectionString

func GetConnectionString(configFilePath string) string

GetConnectionString return the connection string for the database after reading config file for

func GetDBconnection

func GetDBconnection(configFilePath string) *sql.DB

GetDBconnection return the database connection

func ReadAllTablesSchema

func ReadAllTablesSchema(db *sql.DB) map[string]Table

ReadTablesSchema inspects the DB and returns a list of tables

func ReadTablesSchema

func ReadTablesSchema(db *sql.DB, tableNames []string) map[string]Table

Types

type Reference

type Reference struct {
	TableName     string
	ColumnMapping map[string]string
}

Reference represents a foreign key relationship to a Table

type Table

type Table struct {
	Name            string
	Export          bool
	Columns         []string
	UnexportColumns map[string]bool
	ColumnIndexes   map[string]int
	PKColumns       map[string]bool
	PKSequence      string
	UniqueIndexes   map[string]UniqueIndex
	// a unique index is main when it is the preferred "natural" key
	MainUniqueIndexName string
	References          []Reference
	ReferencedBy        []Reference
}

Table represents a DB table to dump

func (*Table) GetFirstReferenceFromColumn

func (table *Table) GetFirstReferenceFromColumn(columnName string) Reference

we are returning just one reference, the first one which uses the column we want

type UniqueIndex

type UniqueIndex struct {
	Name    string
	Columns []string
}

UniqueIndex represents an index among columns of a Table

Jump to

Keyboard shortcuts

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