sqlassert

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 3 Imported by: 0

README

CI Go Reference Go Report Card

sqlassert

Go package with assertion helpers for SQL databases

Use sqlassert in your integration tests or write assertions for schema changes and migraton scripts.

Usage

go get github.com/pengux/sqlassert

Example:

package migration_test

import (
	"testing"

	"github.com/pengux/sqlassert"
)

func TestMigration(t *testing.T) {
	...
	// db is *sql.DB
	pgassert := sqlassert.NewPostgresAsserter(db)

	table := "table_name"
	column := "column_name"
	index := "index_name"
	constraint := "constraint_name"
	id := "123"

	pgassert.TableExists(t, table)
	pgassert.ColumnExists(t, table, column)
	pgassert.ConstraintExists(t, table, column, constraint)
	pgassert.RowExists(t, table, map[string]interface{}{
		"id": id,
	})
	pgassert.IndexExists(t, table, index)
}

Supported databases

  • Postgresql
  • Mysql
  • SQLite
  • Microsoft SQL Server
  • Oracle

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MysqlAsserter added in v0.0.2

type MysqlAsserter struct {
	// contains filtered or unexported fields
}

MysqlAsserter contains assertion helpers for mysqlql databases

func NewMysqlAsserter added in v0.0.2

func NewMysqlAsserter(db *sql.DB) *MysqlAsserter

func (*MysqlAsserter) ColumnExists added in v0.0.2

func (pa *MysqlAsserter) ColumnExists(t testingT, table, column string) bool

func (*MysqlAsserter) ColumnNotExists added in v0.0.2

func (pa *MysqlAsserter) ColumnNotExists(t testingT, table, column string) bool

func (*MysqlAsserter) ColumnOfType added in v1.1.0

func (pa *MysqlAsserter) ColumnOfType(t testingT, table, column, dataType string) bool

func (*MysqlAsserter) ConstraintExists added in v0.0.2

func (pa *MysqlAsserter) ConstraintExists(t testingT, table, constraint string) bool

func (*MysqlAsserter) ConstraintNotExists added in v0.0.2

func (pa *MysqlAsserter) ConstraintNotExists(t testingT, table, constraint string) bool

func (*MysqlAsserter) IndexExists added in v0.0.2

func (pa *MysqlAsserter) IndexExists(t testingT, table, index string) bool

func (*MysqlAsserter) IndexNotExists added in v0.0.2

func (pa *MysqlAsserter) IndexNotExists(t testingT, table, index string) bool

func (*MysqlAsserter) RowExists added in v0.0.2

func (pa *MysqlAsserter) RowExists(t testingT, table string, colVals map[string]interface{}) bool

func (*MysqlAsserter) RowNotExists added in v0.0.2

func (pa *MysqlAsserter) RowNotExists(t testingT, table string, colVals map[string]interface{}) bool

func (*MysqlAsserter) TableExists added in v0.0.2

func (pa *MysqlAsserter) TableExists(t testingT, table string) bool

func (*MysqlAsserter) TableNotExists added in v0.0.2

func (pa *MysqlAsserter) TableNotExists(t testingT, table string) bool

type PostgresAsserter

type PostgresAsserter struct {
	// contains filtered or unexported fields
}

PostgresAsserter contains assertion helpers for Postgresql databases

func NewPostgresAsserter

func NewPostgresAsserter(db *sql.DB) *PostgresAsserter

func (*PostgresAsserter) ColumnExists

func (pa *PostgresAsserter) ColumnExists(t testingT, table, column string) bool

func (*PostgresAsserter) ColumnNotExists

func (pa *PostgresAsserter) ColumnNotExists(t testingT, table, column string) bool

func (*PostgresAsserter) ColumnOfType added in v1.1.0

func (pa *PostgresAsserter) ColumnOfType(t testingT, table, column, dataType string) bool

func (*PostgresAsserter) ConstraintExists

func (pa *PostgresAsserter) ConstraintExists(t testingT, table, constraint string) bool

func (*PostgresAsserter) ConstraintNotExists

func (pa *PostgresAsserter) ConstraintNotExists(t testingT, table, constraint string) bool

func (*PostgresAsserter) IndexExists

func (pa *PostgresAsserter) IndexExists(t testingT, table, index string) bool

func (*PostgresAsserter) IndexNotExists

func (pa *PostgresAsserter) IndexNotExists(t testingT, table, index string) bool

func (*PostgresAsserter) RowExists

func (pa *PostgresAsserter) RowExists(t testingT, table string, colVals map[string]interface{}) bool

func (*PostgresAsserter) RowNotExists

func (pa *PostgresAsserter) RowNotExists(t testingT, table string, colVals map[string]interface{}) bool

func (*PostgresAsserter) TableExists

func (pa *PostgresAsserter) TableExists(t testingT, table string) bool

func (*PostgresAsserter) TableNotExists

func (pa *PostgresAsserter) TableNotExists(t testingT, table string) bool

Jump to

Keyboard shortcuts

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