Documentation ¶
Overview ¶
Package dbschema package implements querying and comparing schemas for testing.
Index ¶
- Constants
- func ValidateColumnName(column string) error
- func ValidateTableName(table string) error
- type Column
- type ColumnData
- type Data
- type Index
- type Queryer
- type Reference
- type RowData
- type Schema
- func (schema *Schema) DropIndex(name string)
- func (schema *Schema) DropTable(tableName string)
- func (schema *Schema) EnsureTable(tableName string) *Table
- func (schema *Schema) FindIndex(name string) (*Index, bool)
- func (schema *Schema) FindTable(tableName string) (*Table, bool)
- func (schema *Schema) Sort()
- func (schema Schema) String() string
- type Sections
- type Snapshot
- type Snapshots
- type Table
- type TableData
Constants ¶
const ( NewData = "NEW DATA" OldData = "OLD DATA" Main = "MAIN" MainData = "MAIN DATA" )
These consts are the names of the sections that are typical in our scripts.
Variables ¶
This section is empty.
Functions ¶
func ValidateColumnName ¶ added in v1.7.1
ValidateColumnName checks column has at least 1 character and it's only formed by lower and upper case letters, numbers, underscores or dashes where dashes cannot be at the beginning of the end and not in a row.
func ValidateTableName ¶ added in v1.7.1
ValidateTableName checks table has at least 1 character and it's only formed by lower and upper case letters, numbers, underscores or dashes where dashes cannot be at the beginning of the end and not in a row. One dot is allowed for scoping tables in a schema (e.g. public.my_table).
Types ¶
type ColumnData ¶ added in v1.6.1
ColumnData is a value of a column within a row.
func (ColumnData) String ¶ added in v1.6.1
func (c ColumnData) String() string
String returns a string representation of the column.
type Data ¶
type Data struct {
Tables []*TableData
}
Data is the database content formatted as strings.
func QueryData ¶
func QueryData(ctx context.Context, db Queryer, schema *Schema, quoteColumn func(string) string) (*Data, error)
QueryData loads all data from tables.
type Index ¶
type Index struct { Name string Table string Columns []string Unique bool Partial string // partial expression }
Index is an index for a table.
type Queryer ¶
type Queryer interface { // QueryRowContext executes a query that returns a single row. QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row // QueryContext executes a query that returns rows, typically a SELECT. QueryContext(ctx context.Context, query string, args ...interface{}) (tagsql.Rows, error) }
Queryer is a representation for something that can query.
type Schema ¶
Schema is the database structure.
func (*Schema) EnsureTable ¶
EnsureTable returns the table with the specified name and creates one if needed.
type Sections ¶ added in v1.6.1
Sections is a type to keep track of the sections inside of a sql script.
func NewSections ¶ added in v1.6.1
NewSections constructs a Sections from a sql script.
func (Sections) LookupSection ¶ added in v1.6.1
LookupSection finds the named section in the script or returns an empty string.
type Snapshots ¶
type Snapshots struct {
List []*Snapshot
}
Snapshots defines a collection of snapshot.
func (*Snapshots) FindVersion ¶
FindVersion finds a snapshot with the specified version.
type Table ¶
Table is a sql table.
func (*Table) ColumnNames ¶
ColumnNames returns column names.
func (*Table) FindColumn ¶
FindColumn finds a column in the table.
func (*Table) RemoveColumn ¶ added in v1.25.2
RemoveColumn removes the column from the table.