Documentation
¶
Index ¶
- func QuoteConstraint(def string, contype string) string
- func QuoteIdentifier(name string) string
- func QuoteIndex(def string) string
- type Column
- type Database
- func (db *Database) GenTable(ctx context.Context, schema, table string, cols []Column) (string, error)
- func (db *Database) GetColumnDetail(ctx context.Context, schema, table string) ([]Column, error)
- func (db *Database) GetInheritance(ctx context.Context, schema, table string) ([]Inheritance, error)
- func (db *Database) GetMatViewDetails(ctx context.Context, schema, matview string) (string, error)
- func (db *Database) GetOwnershipAndPrivileges(ctx context.Context, schema, name, kind string) (string, error)
- func (db *Database) GetRoutine(schema string, r Routine) string
- func (db *Database) GetRoutineSchema(ctx context.Context, schema, routine string) ([]Routine, error)
- func (db *Database) GetRoutines(ctx context.Context, schema string) ([]string, error)
- func (db *Database) GetSchemas(ctx context.Context) ([]Schema, error)
- func (db *Database) GetSequenceDetails(ctx context.Context, schema, name string) (string, error)
- func (db *Database) GetSequences(ctx context.Context, schema string) ([]Sequence, error)
- func (db *Database) GetTableComment(ctx context.Context, schema, table string) (string, error)
- func (db *Database) GetTableConstraints(ctx context.Context, schema, table string) (string, error)
- func (db *Database) GetTableData(ctx context.Context, schema, table string) (string, error)
- func (db *Database) GetTableIndexes(ctx context.Context, schema, table string) (string, error)
- func (db *Database) GetTableSchema(ctx context.Context, schema, table string) (string, error)
- func (db *Database) GetTables(ctx context.Context, schema string, kind RelKind) ([]Table, error)
- func (db *Database) GetViewDetails(ctx context.Context, schema, view string) (string, error)
- func (db *Database) OpenDatabase() error
- func (db *Database) WriteTableData(ctx context.Context, w io.Writer, schema, table string) (retErr error)
- type Index
- type Inheritance
- type RelKind
- type Routine
- type Schema
- type Sequence
- type Table
- type TableConstraint
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QuoteConstraint ¶
func QuoteIdentifier ¶
func QuoteIndex ¶
Types ¶
type Column ¶
type Column struct {
ColumnName string `db:"column_name"`
IsNullable string `db:"is_nullable"`
ColumnDefault *string `db:"column_default"`
DataType string `db:"data_type"`
Comment string `db:"column_comment"`
IsLocal bool `db:"is_local"`
}
Column details using pg_catalog
type Database ¶
type Database struct {
Hostname string
Port int
Database string
Username string
Password string
URI string
SSLMode string // default "disable"
Timeout int
DataOnly bool
SchemaOnly bool
IfExists bool
File string
IncludeSchemas []string
IncludeTables []string
NoOwner bool
NoPrivileges bool
*sqlx.DB
}
Database holds connection config and a live *sqlx.DB.
func NewDatabase ¶
func NewDatabase() *Database
func (*Database) GenTable ¶
func (db *Database) GenTable(ctx context.Context, schema, table string, cols []Column) (string, error)
GenTable generates a CREATE TABLE DDL statement.
func (*Database) GetColumnDetail ¶
func (*Database) GetInheritance ¶
func (*Database) GetMatViewDetails ¶
GetMatViewDetails returns the DDL for a materialized view.
func (*Database) GetOwnershipAndPrivileges ¶
func (*Database) GetRoutine ¶
GetRoutine returns the SQL DDL for a single routine overload. pg_get_functiondef already returns a complete CREATE OR REPLACE statement.
func (*Database) GetRoutineSchema ¶
func (db *Database) GetRoutineSchema(ctx context.Context, schema, routine string) ([]Routine, error)
GetRoutineSchema returns all overloads of a routine (function or procedure). pg_get_functiondef returns a complete CREATE OR REPLACE statement for both functions and procedures in PG11+, so we use it for both kinds.
func (*Database) GetRoutines ¶
GetRoutines returns the distinct routine names in a schema.
func (*Database) GetSchemas ¶
GetSchemas returns schema list
func (*Database) GetSequenceDetails ¶
func (*Database) GetSequences ¶
func (*Database) GetTableComment ¶
func (*Database) GetTableConstraints ¶
func (*Database) GetTableData ¶
GetTableData returns COPY-format table data as a string. Prefer WriteTableData for production use to avoid buffering large tables.
func (*Database) GetTableIndexes ¶
func (*Database) GetTableSchema ¶
GetTableSchema gets the full DDL for a table.
func (*Database) GetViewDetails ¶
func (*Database) OpenDatabase ¶
func (*Database) WriteTableData ¶
func (db *Database) WriteTableData(ctx context.Context, w io.Writer, schema, table string) (retErr error)
WriteTableData streams COPY-format table data directly to w, avoiding buffering the entire table in memory. The caller is responsible for buffering w (e.g. via bufio.Writer) if needed.
type Inheritance ¶
type RelKind ¶
type RelKind string
RelKind represents a pg_class.relkind value.
const ( RelkindTable RelKind = "r" // ordinary table RelkindView RelKind = "v" // view RelkindMatView RelKind = "m" // materialized view RelkindPartitionedTable RelKind = "p" // partitioned table — TODO: dump PARTITION BY clauses RelkindForeignTable RelKind = "f" // foreign table — TODO: dump CREATE FOREIGN TABLE ... SERVER )
relkind constants per pg_class.relkind
type Routine ¶
type Routine struct {
Name string `db:"routine_name"`
Type string `db:"routine_type"`
Definition string `db:"routine_definition"`
}
Routine holds the DDL for a single function or procedure overload.