sqlx

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MySQLDialect     = "mysql"
	MariaDBDialect   = MySQLDialect
	PostgresDialect  = "postgres"
	OracleDialect    = "oracle"
	SQLServerDialect = "mssql"
)
View Source
const (
	StatementTypeTCLBegin = iota + StatementTypeTCL
	StatementTypeTCLEnd
)
View Source
const (
	StatementTypeDMLSingle = iota + StatementTypeDML
	StatementTypeDMLMultiple
)

Variables

This section is empty.

Functions

func Exec added in v0.2.0

func Exec(ctx context.Context, ex Executor, sql string, args ...any) error

Exec executes the given SQL with the executor.

func IsDatabaseConnected

func IsDatabaseConnected(ctx context.Context, db *sql.DB) (perr error)

func LoadDatabase

func LoadDatabase(addr string, addrConnMax int) (drv string, db *sql.DB, err error)

func ParseAddress

func ParseAddress(addr string) (drv, dsn string, err error)

Types

type DMLInsert added in v0.2.0

type DMLInsert struct {
	Prefix string
	Values []string
}

type DMLLevel added in v0.2.0

type DMLLevel = uint
const (
	SingleSessionDML DMLLevel = iota + 1
	MultiSessionsDML
)

type Executor added in v0.2.0

type Executor interface {
	ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error)
}

type Parsed added in v0.2.0

type Parsed interface {
	// Origin returns the original SQL.
	Origin() string
	// Unknown returns true if not matched any languages.
	Unknown() bool
	// TCL returns the TCLLevel and true if the Origin is transaction control language.
	TCL() (TCLLevel, bool)
	// DCL returns true if the Origin is data control language.
	DCL() bool
	// DDL returns true if the Origin is data definition language.
	DDL() bool
	// DML returns the DMLLevel and true if the Origin is data manipulation language.
	DML() (DMLLevel, bool)
	// AsDMLInsert returns the structuring insert statement if possible.
	AsDMLInsert() (DMLInsert, bool)
}

func Parse added in v0.2.0

func Parse(drv, sql string) Parsed

type StatementType added in v0.2.3

type StatementType = uint
const (
	StatementTypeUnknown StatementType
	StatementTypeTCL
	StatementTypeDCL
	StatementTypeDDL
	StatementTypeDML
)

func Preview added in v0.2.3

func Preview(sql string) StatementType

Preview analyzes the beginning of the query using a simpler and faster textual comparison to identify the statement type, borrows from the vitess.io/vitess/go/vt/sqlparser.

type TCLLevel added in v0.2.0

type TCLLevel = uint
const (
	StartTCL TCLLevel = iota + 1
	EndTCL
)

Jump to

Keyboard shortcuts

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