Documentation
¶
Overview ¶
schemaspy reads the definition of a PostgreSQL schema: tables, functions, indexes &c. and returns it as a datastructure.
It can't change things; the use case is for maintenance and setup scripts which need to inspect the current state of the database. Those scripts are expected to draw their conclusions and if needed apply their changes with `ALTER` commands.
Example ¶
package main
import (
"fmt"
"log"
"github.com/alicebob/schemaspy"
)
func main() {
pgURL := "postgres://localhost"
schema, err := schemaspy.Public(pgURL)
if err != nil {
log.Fatal(err)
}
fmt.Printf("schema: %s\n", schema.Name)
for _, t := range schema.Tables {
table := schema.Relations[t]
fmt.Printf("table: %s (%d cols)\n", t, len(table.Columns))
for _, index := range table.Indexes {
fmt.Printf(" index: %s\n", index)
}
}
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Relation ¶
type Relation struct {
// Type is "table", "view", or "materialized view"
Type string
Columns map[string]Column
Inherits []string
Children []string
Indexes []string
}
Relation is a table, view, or materialized view.
func (*Relation) ColumnNames ¶
ColumnNames lists all columns in database order
type Schema ¶
type Schema struct {
Name string
// Relations are all tables, views, and materialized views
Relations map[string]Relation
// all plain tables, ordered alphabetically. Every table has an entry in
// Relations
Tables []string
// all views, ordered alphabetically. Every view has an entry in Relations
Views []string
// all materialized views, ordered alphabetically. Every materialized view
// has an entry in Relations
Materialized []string
Sequences map[string]Sequence
Indexes map[string]Index
Functions map[string]Function
}
func DescribeConn ¶
Describe a schema. Leave schema empty for the public schema.
func DescribeTx ¶
Describe a schema. Leave schema empty for the public schema.
Click to show internal directories.
Click to hide internal directories.