sqlsmith

package module
v0.0.0-...-0cdfd1f Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 14 Imported by: 1

README

SQLsmith-GO

Go version of SQLsmith.

Usage

import (
	sqlsmith_go "github.com/pingcap/tipocket/go-sqlsmith"
)

func gosmith() {
	ss := sqlsmith_go.New()

	// load schema
	ss.LoadSchema([][5]string{
		// members table
		[5]string{"games", "members", "BASE TABLE", "id", "int(11)"},
		[5]string{"games", "members", "BASE TABLE", "name", "varchar(255)"},
		[5]string{"games", "members", "BASE TABLE", "age", "int(11)"},
		[5]string{"games", "members", "BASE TABLE", "team_id", "int(11)"},
		// teams table
		[5]string{"games", "teams", "BASE TABLE", "id", "int(11)"},
		[5]string{"games", "teams", "BASE TABLE", "team_name", "varchar(255)"},
		[5]string{"games", "teams", "BASE TABLE", "created_at", "timestamp"},
	})

	// use games database
	ss.SetDB("games")

	// generate select statement AST without scema information
	node := ss.SelectStmt(5)

	// fill the tree with selected schema and get SQL string
	sql, err := ss.Walk(node)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataGenerator

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

DataGenerator defines data generator

func (*DataGenerator) Next

func (d *DataGenerator) Next() []string

Next returns data batch

type SQLSmith

type SQLSmith struct {
	Rand      *rand.Rand
	Databases map[string]*types.Database

	Node ast.Node
	// contains filtered or unexported fields
}

SQLSmith defines SQLSmith struct

func New

func New() *SQLSmith

New create SQLSmith instance

func (*SQLSmith) BatchData

func (s *SQLSmith) BatchData(total, batchSize int) ([]string, error)

BatchData generate testing data by schema in given batch return SQLs with insert statement

func (*SQLSmith) CreateTableStmt

func (s *SQLSmith) CreateTableStmt() (string, error)

CreateTableStmt create table

func (*SQLSmith) Debug

func (s *SQLSmith) Debug()

Debug turn on debug mode

func (*SQLSmith) GenData

func (s *SQLSmith) GenData(total, batch int) (*DataGenerator, error)

GenData returns data generator

func (*SQLSmith) GetCurrDBName

func (s *SQLSmith) GetCurrDBName() string

GetCurrDBName returns current selected dbname

func (*SQLSmith) GetDB

func (s *SQLSmith) GetDB(db string) *types.Database

GetDB get current database without nil

func (*SQLSmith) InsertStmt

func (s *SQLSmith) InsertStmt(fn bool) (string, error)

InsertStmt make random insert statement SQL

func (*SQLSmith) InsertStmtAST

func (s *SQLSmith) InsertStmtAST() (string, error)

InsertStmtAST implement insert statement from AST

func (*SQLSmith) LoadSchema

func (s *SQLSmith) LoadSchema(records [][5]string)

LoadSchema init schemas, tables and columns record[0] dbname record[1] table name record[2] table type record[3] column name record[4] column type

func (*SQLSmith) SelectStmt

func (s *SQLSmith) SelectStmt(depth int) (string, error)

SelectStmt make random select statement SQL

func (*SQLSmith) SetDB

func (s *SQLSmith) SetDB(db string)

SetDB set current database

func (*SQLSmith) SetStable

func (s *SQLSmith) SetStable(stable bool)

SetStable set stable to given value

func (*SQLSmith) Stable

func (s *SQLSmith) Stable()

Stable set generated SQLs no rand

func (*SQLSmith) UpdateStmt

func (s *SQLSmith) UpdateStmt() (string, error)

UpdateStmt make random update statement SQL

func (*SQLSmith) Walk

func (s *SQLSmith) Walk(tree ast.Node) (string, error)

Walk will walk the tree and fillin tables and columns data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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