dbschema

package
v0.27.0-rc-crdb Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dbschema package implements querying and comparing schemas for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

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

Column is a sql column.

type Data

type Data struct {
	Tables []*TableData
}

Data is the database content formatted as strings

func QueryData

func QueryData(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.

type Queryer

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

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.

type RowData

type RowData []string

RowData is content of a single row

func (RowData) Clone

func (row RowData) Clone() RowData

Clone returns a clone of row data.

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

type Snapshot

type Snapshot struct {
	Version int
	Script  string
	*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

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)

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