dbschema

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dbschema package implements querying and comparing schemas for testing.

Index

Constants

View Source
const (
	NewData = "NEW DATA"
	OldData = "OLD DATA"
	Main    = "MAIN"
)

These consts are the names of the sections that are typical in our scripts.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name       string
	Type       string
	IsNullable bool
	Default    string
	Reference  *Reference
}

Column is a sql column.

func (Column) String added in v0.35.2

func (column Column) String() string

type ColumnData added in v1.6.1

type ColumnData struct {
	Column string
	Value  string
}

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

func (*Data) AddTable

func (data *Data) AddTable(table *TableData)

AddTable adds a new table.

func (*Data) FindTable

func (data *Data) FindTable(tableName string) (*TableData, bool)

FindTable finds a table by name

func (*Data) Sort

func (data *Data) Sort()

Sort sorts all 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.

func (Index) String added in v0.35.2

func (index Index) String() string

type Queryer

type Queryer interface {
	// QueryContext executes a query that returns rows, typically a SELECT.
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

	// QueryRowContext executes a query that returns a single row.
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

Queryer is a representation for something that can query.

type Reference

type Reference struct {
	Table    string
	Column   string
	OnDelete string
	OnUpdate string
}

Reference is a column foreign key.

func (*Reference) String added in v0.35.2

func (reference *Reference) String() string

type RowData

type RowData []ColumnData

RowData is content of a single row

func (RowData) Clone

func (row RowData) Clone() RowData

Clone returns a clone of row data.

func (RowData) Less added in v1.6.1

func (row RowData) Less(b RowData) bool

Less returns true if one row is less than the other.

type Schema

type Schema struct {
	Tables  []*Table
	Indexes []*Index
}

Schema is the database structure.

func (*Schema) DropTable

func (schema *Schema) DropTable(tableName string)

DropTable removes the specified table

func (*Schema) EnsureTable

func (schema *Schema) EnsureTable(tableName string) *Table

EnsureTable returns the table with the specified name and creates one if needed.

func (*Schema) Sort

func (schema *Schema) Sort()

Sort sorts tables and indexes

func (Schema) String added in v0.35.2

func (schema Schema) String() string

type Sections added in v1.6.1

type Sections struct {
	Script   string
	Sections map[string]string
}

Sections is a type to keep track of the sections inside of a sql script.

func NewSections added in v1.6.1

func NewSections(script string) Sections

NewSections constructs a Sections from a sql script.

func (Sections) LookupSection added in v1.6.1

func (s Sections) LookupSection(section string) string

LookupSection finds the named section in the script or returns an empty string.

type Snapshot

type Snapshot struct {
	Version int
	Sections
	*Schema
	*Data
}

Snapshot defines a particular snapshot of schema and data.

type Snapshots

type Snapshots struct {
	List []*Snapshot
}

Snapshots defines a collection of snapshot

func (*Snapshots) Add

func (snapshots *Snapshots) Add(snap *Snapshot)

Add adds a new snapshot.

func (*Snapshots) FindVersion

func (snapshots *Snapshots) FindVersion(version int) (*Snapshot, bool)

FindVersion finds a snapshot with the specified version.

func (*Snapshots) Sort

func (snapshots *Snapshots) Sort()

Sort sorts the snapshots by version

type Table

type Table struct {
	Name       string
	Columns    []*Column
	PrimaryKey []string
	Unique     [][]string
}

Table is a sql table.

func (*Table) AddColumn

func (table *Table) AddColumn(column *Column)

AddColumn adds the column to the table.

func (*Table) ColumnNames

func (table *Table) ColumnNames() []string

ColumnNames returns column names

func (*Table) FindColumn

func (table *Table) FindColumn(columnName string) (*Column, bool)

FindColumn finds a column in the table

func (*Table) Sort

func (table *Table) Sort()

Sort sorts columns, primary keys and unique

func (Table) String added in v0.35.2

func (table Table) String() string

type TableData

type TableData struct {
	Name    string
	Columns []string
	Rows    []RowData
}

TableData is content of a sql table

func (*TableData) AddRow

func (table *TableData) AddRow(row RowData) error

AddRow adds a new row.

func (*TableData) Sort

func (table *TableData) Sort()

Sort sorts all rows.

Jump to

Keyboard shortcuts

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