conf

package
v0.0.0-...-75cd591 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 59 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DisplayDefault = 1 << iota // 1 << 0 which is 00000001
	DisplayVertical
	DisplayInsertSQL
	DisplayJSON
	DisplayJSONFree
)

Variables

View Source
var UsingPing = ParseBool(os.Getenv("PING"), true)

Functions

func AbbreviateSlice

func AbbreviateSlice(r []any, maxLen int) []any

func AutoTestConnect

func AutoTestConnect(dsnSource string) (driverName, fixedDataSourceName string)

func Exec

func Exec(ctx context.Context, db DBExecAware, q string, args []any, rowsScanner sqlmap.RowsScanner) error

func FirstTimeQuery

func FirstTimeQuery(query string, tags []*Pos) string

func FormatFloat64

func FormatFloat64(f float64) string

FormatFloat64 formats a float64 number to a string with the specified precision. If the fractional part is all zeros, it returns the integer part only.

func FullQuery

func FullQuery(query string, tags []*Pos) string

func GetBindPlaceholder

func GetBindPlaceholder(driverName string) func(seq int) string

func GoWait

func GoWait(threads int, f func(threadNum int) error, errHandler func(error)) time.Duration

func IsUsingDB

func IsUsingDB(q string) bool

func NewCachingSubstituter

func NewCachingSubstituter() jj.Substitute

func NewUpdateRowsScanner

func NewUpdateRowsScanner() *updateRowsScanner

func Parse

func Parse(sql string, dbDialect dialect.Dialect, mode sqlparser.Mode) (sqlparser.Statement, error)

Parse using default dialect MySQl (for backward compatibility)

func ParseBool

func ParseBool(s string, defaultValue bool) bool

ParseBool returns the boolean value represented by the string. It accepts 1, t, true, y, yes, on as true with camel case incentive and accepts 0, f false, n, no, off as false with camel case incentive Any other value returns an error.

func ParseSQL

func ParseSQL(placeholder BindNameAware, sql string) (parsedQuery sqlparser.Statement, varSubs []ss.Subs, err error)

ParseSQL returns a normalized (lowercase's SQL commands) SQL string, and redacted SQL string with the params stripped out for display. Taken from sqlparser package

func ParseSubstitute

func ParseSubstitute(s string) (parts ss.Parts)

func PingDB

func PingDB(ctx context.Context, db any, timeout time.Duration) error

func Query

func Query(ctx context.Context, db sqlmap.Queryer, q string, args []any, formatter sqlmap.RowsScanner, options ...sqlmap.ScanConfigFn) error

func ReadEnvFile

func ReadEnvFile(filename string) (envMap map[string][]string, err error)

func RepeatValues

func RepeatValues(values string, fn BindNameAware, batch int) string

func RunSQL

func RunSQL(ctx context.Context, db DB, driverName, q string, option RunSQLOption) error

func WithSignal

func WithSignal(ctx context.Context, timeout time.Duration, sig ...os.Signal) (context.Context, context.CancelFunc)

Types

type Action

type Action struct {
	LabelQuery string `yaml:"labelQuery"`
	Sqls       []*Sql `yaml:"sqls"`

	Disabled bool `yaml:"disabled"`
	// contains filtered or unexported fields
}

func (*Action) Go

func (a *Action) Go(dss []*DataSource, r *replOptions) (namedSqls []DsSql)

type Bar

type Bar interface {
	Add(value int)
	Finish()
}

type Batch

type Batch struct {
	LastQuery string
	NArgs     int
}

type BindNameAware

type BindNameAware interface {
	CurrentSeq() int
	NextBindName() string
	BindName(seq int) string
	GetDialect() dialect.Dialect
}

type BindNameMssql

type BindNameMssql struct {
	Seq
}

func (*BindNameMssql) BindName

func (s *BindNameMssql) BindName(seq int) string

func (*BindNameMssql) GetDialect

func (s *BindNameMssql) GetDialect() dialect.Dialect

func (*BindNameMssql) NextBindName

func (s *BindNameMssql) NextBindName() string

type BindNameMySQL

type BindNameMySQL struct {
	Seq
}

func (*BindNameMySQL) BindName

func (s *BindNameMySQL) BindName(seq int) string

func (*BindNameMySQL) GetDialect

func (s *BindNameMySQL) GetDialect() dialect.Dialect

func (*BindNameMySQL) NextBindName

func (s *BindNameMySQL) NextBindName() string

type BindNameOracle

type BindNameOracle struct {
	Seq
}

func (*BindNameOracle) BindName

func (s *BindNameOracle) BindName(seq int) string

func (*BindNameOracle) GetDialect

func (s *BindNameOracle) GetDialect() dialect.Dialect

func (*BindNameOracle) NextBindName

func (s *BindNameOracle) NextBindName() string

type BindNamePg

type BindNamePg struct {
	Seq
}

func (*BindNamePg) BindName

func (s *BindNamePg) BindName(seq int) string

func (*BindNamePg) GetDialect

func (s *BindNamePg) GetDialect() dialect.Dialect

func (*BindNamePg) NextBindName

func (s *BindNamePg) NextBindName() string

type ColName

type ColName struct {
	*sqlparser.ColName
	BindVar string
}

func (*ColName) Format

func (node *ColName) Format(buf *sqlparser.TrackedBuffer)

Format formats the node.

type Config

type Config struct {
	Prompt      string        `yaml:"prompt" default:"always"`
	ListenAddr  string        `yaml:"listenAddr"`
	ContextPath string        `yaml:"contextPath" default:"/"`
	DataSources []*DataSource `yaml:"dataSources"`

	Actions []*Action `yaml:"actions"`
	Offset  int       `yaml:"offset"`
	Limit   int       `yaml:"limit" default:"1000"`
}

func ParseConfigFile

func ParseConfigFile(filePath, driverName string) (*Config, error)

func (*Config) Go

func (c *Config) Go(dsn string, evaluates, args []string)

type DB

type DB interface {
	sqlmap.Queryer
	DBExecAware
}

type DBExecAware

type DBExecAware interface {
	// ExecContext executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

type DSNItem

type DSNItem struct {
	DSN   string
	Title string
}

func (DSNItem) ItemDesc

func (d DSNItem) ItemDesc() string

func (DSNItem) ItemTitle

func (d DSNItem) ItemTitle() string

type DataSource

type DataSource struct {
	Labels map[string]string `yaml:"labels"`

	Name          string `yaml:"name"`
	DriverName    string `yaml:"driverName"`
	DataSourceURL string `yaml:"dataSourceName"`
	DataSourceEnv string `yaml:"dataSourceEnv"`

	Disabled bool `yaml:"disabled"`
	// contains filtered or unexported fields
}

func (*DataSource) Close

func (d *DataSource) Close() error

func (*DataSource) Connect

func (d *DataSource) Connect(panicOnError bool, verbose int, maxOpenConns int) (err error)

func (*DataSource) GetDataSourceName

func (d *DataSource) GetDataSourceName() string

func (*DataSource) ItemDesc

func (d *DataSource) ItemDesc() string

func (*DataSource) ItemTitle

func (d *DataSource) ItemTitle() string

type DisplayMode

type DisplayMode int

type DsSql

type DsSql struct {
	DS *DataSource
	*Sql
}

type FindOption

type FindOption struct {
	Open, Close rune
	Quote       rune
}

func (*FindOption) FindNamed

func (f *FindOption) FindNamed(s string) (names []*Pos)

func (*FindOption) FindTags

func (f *FindOption) FindTags(s string) (tags []*Pos)

type FuncExpr

type FuncExpr struct {
	*sqlparser.FuncExpr
	BindVar string
}

func (*FuncExpr) Format

func (node *FuncExpr) Format(buf *sqlparser.TrackedBuffer)

Format formats the node.

type HTTPRowsScanner

type HTTPRowsScanner struct {
	Header []string

	Limit, Offset int
	// contains filtered or unexported fields
}

func NewHTTPRowsScanner

func NewHTTPRowsScanner(limit, offset int, writer io.Writer) *HTTPRowsScanner

func (*HTTPRowsScanner) AddRow

func (j *HTTPRowsScanner) AddRow(rowIndex int, columns []any) bool

func (*HTTPRowsScanner) Complete

func (j *HTTPRowsScanner) Complete()

func (*HTTPRowsScanner) StartExecute

func (j *HTTPRowsScanner) StartExecute(string)

func (*HTTPRowsScanner) StartRows

func (j *HTTPRowsScanner) StartRows(_ string, header []string, _ int)

type InsertRowsScanner

type InsertRowsScanner struct {
	Header        []string
	Limit, Offset int
	// contains filtered or unexported fields
}

func NewInsertRowsScanner

func NewInsertRowsScanner(limit, offset int) *InsertRowsScanner

func (*InsertRowsScanner) AddRow

func (j *InsertRowsScanner) AddRow(rowIndex int, columns []any) bool

func (*InsertRowsScanner) Complete

func (j *InsertRowsScanner) Complete()

func (*InsertRowsScanner) SingleQuote

func (j *InsertRowsScanner) SingleQuote() bool

func (*InsertRowsScanner) StartExecute

func (j *InsertRowsScanner) StartExecute(query string)

func (*InsertRowsScanner) StartRows

func (j *InsertRowsScanner) StartRows(query string, header []string, options int)

type JsonRowsScanner

type JsonRowsScanner struct {
	Header        []string
	Limit, Offset int

	Vertical      bool
	FreeInnerJSON bool
	// contains filtered or unexported fields
}

func NewJsonRowsScanner

func NewJsonRowsScanner(offset, limit int, vertical, freeInnerJSON bool) *JsonRowsScanner

func (*JsonRowsScanner) AddRow

func (j *JsonRowsScanner) AddRow(rowIndex int, columns []any) bool

func (*JsonRowsScanner) Complete

func (j *JsonRowsScanner) Complete()

func (*JsonRowsScanner) StartExecute

func (j *JsonRowsScanner) StartExecute(string)

func (*JsonRowsScanner) StartRows

func (j *JsonRowsScanner) StartRows(_ string, header []string, options int)

type LogOption

type LogOption struct {
	Interval time.Duration
	Preview  int
	Rows     int
	All      bool
}

func ParseLogOptions

func ParseLogOptions(option string) (logOpt *LogOption, err error)

type LogState

type LogState struct {
	Last     time.Time
	Opt      *LogOption
	Rows     int
	LogTimes int
}

func (*LogState) AddRows

func (s *LogState) AddRows(rows int)

func (*LogState) Log

func (s *LogState) Log(fmt string, args ...any)

type ParseResult

type ParseResult struct {
	Tags  []*Pos
	Names []*Pos
}

type Perf

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

func NewPerf

func NewPerf(query string, options *replOptions, thinkTime *tick.ThinkTime) *Perf

type Pos

type Pos struct {
	From, To int
	ArgOpen  int
}

type QueryRowsStepper

type QueryRowsStepper struct {
	Rows  []map[string]any
	Index int
}

func (*QueryRowsStepper) HasNext

func (s *QueryRowsStepper) HasNext() bool

func (*QueryRowsStepper) Step

func (s *QueryRowsStepper) Step(state map[string]any) bool

type RunSQLOption

type RunSQLOption struct {
	RowsScanner   sqlmap.RowsScanner
	Lookup        map[string]map[string]string
	Format        string
	RawFileDir    string
	RawFileExt    string
	Offset, Limit int
	DisplayMode   int
	Timeout       time.Duration // SQL 执行超时时间
	MaxLen        int
	PrintCost     bool
	SaveResult    bool
	TempResultDB  bool
	ShowRowIndex  bool
	NoEvalSQL     bool // 评估 SQL,提取常量为占位符,估算 @name 值等
	DryRun        bool
	ParsePrepared bool
	AsQuery       bool // 强制作为 query 执行(有结果集处理)
	AsExec        bool // 强制作为 更新执行(不处理结果集)
}

func (*RunSQLOption) GetRowsScanner

func (r *RunSQLOption) GetRowsScanner() sqlmap.RowsScanner

type SQLVal

type SQLVal struct {
	*sqlparser.SQLVal
}

func (*SQLVal) Format

func (node *SQLVal) Format(buf *sqlparser.TrackedBuffer)

Format formats the node.

type Seq

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

func (*Seq) CurrentSeq

func (s *Seq) CurrentSeq() int

type Sql

type Sql struct {
	RowsScanner sqlmap.RowsScanner `yaml:"-"`

	Name string `yaml:"name"` // SQL 名字,用于提示列表
	Sql  string `yaml:"sql"`

	// Format 格式化输出
	// NONE 不输出
	// JSON 使用 JSON 格式化输出
	// TABLE 使用表格形式的格式化
	// MARKDOWN 使用 MARKDOWN 格式化输出
	Format string `yaml:"format"`

	// Iterations 表示 SQL 执行次数
	Iterations int `yaml:"iterations"`

	AutoExecute bool `yaml:"autoExecute"` // 有名 SQL 是否自动执行,只有在 Name 有值时起作用
	Disabled    bool `yaml:"disabled"`
	IgnoreError bool `yaml:"ignoreError"`

	// SingleOne 只执行第一条 SQL
	SingleOne bool `yaml:"singleOne"`
	// contains filtered or unexported fields
}

func (*Sql) ItemDesc

func (c *Sql) ItemDesc() string

func (*Sql) ItemTitle

func (c *Sql) ItemTitle() string

func (*Sql) Run

func (c *Sql) Run(ds *DataSource, options *replOptions)

type SubVars

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

type TableRowsScanner

type TableRowsScanner struct {
	Table  table.Writer
	Format string
	Header []string

	Limit, Offset int

	RowVertical bool
	// contains filtered or unexported fields
}

func NewTableRowsScanner

func NewTableRowsScanner(format string, offset, limit int, rowVertical bool) *TableRowsScanner

func (*TableRowsScanner) AddRow

func (t *TableRowsScanner) AddRow(rowIndex int, columns []any) bool

func (TableRowsScanner) Complete

func (t TableRowsScanner) Complete()

func (*TableRowsScanner) StartExecute

func (t *TableRowsScanner) StartExecute(string)

func (*TableRowsScanner) StartRows

func (t *TableRowsScanner) StartRows(_ string, header []string, options int)

type Tx

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

type TxAware

type TxAware interface {
	Begin() (*sql.Tx, error)
}

type TxContextAware

type TxContextAware interface {
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
}

Jump to

Keyboard shortcuts

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