dbal

package
v0.0.0-...-60a21d4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BindingKeys = []string{
	"select", "from", "join", "where",
	"groupBy", "having",
	"order",
	"union", "unionOrder",
	"sql",
}
View Source
var Grammars = map[string]Grammar{}
View Source
var Operators = []string{
	"=", "<", ">", "<=", ">=", "<>", "!=", "<=>",
	"like", "like binary", "not like", "ilike",
	"&", "|", "^", "<<", ">>",
	"rlike", "not rlike", "regexp", "not regexp",
	"~", "~*", "!~", "!~*", "similar to",
	"not similar to", "not ilike", "~~*", "!~~*",
}

Functions

func IsExpression

func IsExpression(value interface{}) bool

func Register

func Register(name string, grammar Grammar)

Types

type Aggregate

type Aggregate struct {
	Func    string
	Columns []interface{}
}

type Column

type Column struct {
	DBName                   string      `db:"db_name"`
	TableName                string      `db:"table_name"`
	Name                     string      `db:"name"`
	Position                 int         `db:"position"`
	Default                  interface{} `db:"default"`
	DefaultRaw               string      `db:"default_raw"`
	Nullable                 bool        `db:"nullable"`
	IsUnsigned               bool        `db:"unsigned"`
	Type                     string      `db:"type"`
	Length                   *int        `db:"length"`
	OctetLength              *int        `db:"octet_length"`
	Precision                *int        `db:"precision"`
	Scale                    *int        `db:"scale"`
	DateTimePrecision        *int        `db:"datetime_precision"`
	Charset                  *string     `db:"charset"`
	Collation                *string     `db:"collation"`
	Key                      *string     `db:"key"`
	Extra                    *string     `db:"extra"`
	Comment                  *string     `db:"comment"`
	Primary                  bool        `db:"primary"`
	TypeName                 string      `db:"type_name"`
	MaxLength                int
	DefaultLength            int
	MaxPrecision             int
	DefaultPrecision         int
	MaxScale                 int
	DefaultScale             int
	MaxDateTimePrecision     int
	DefaultDateTimePrecision int
	Option                   []string
	Table                    *Table
	Indexes                  []*Index
	Constraint               *Constraint
}

type Command

type Command struct {
	Name    string
	Params  []interface{}
	Success func()
	Fail    func()
}

func (*Command) Callback

func (command *Command) Callback(err error)

type Config

type Config struct {
	Driver   string `json:"driver"`
	DSN      string `json:"dsn"`
	Name     string `json:"name"`
	ReadOnly bool   `json:"readonly,omitempty"`
}

type Connection

type Connection struct {
	DB      *sqlx.DB
	Config  *Config
	Option  *Option
	Version *Version
}

type Constraint

type Constraint struct {
	SchemaName string
	TableName  string
	ColumnName string
	Type       string
	Args       []string
	Table      *Table
}

func NewConstraint

func NewConstraint(schemaName string, tableName string, columnName string) *Constraint

type Expression

type Expression struct {
	Value interface{}
}

func NewExpression

func NewExpression(value interface{}) Expression

func Raw

func Raw(value interface{}) Expression

func (Expression) GetValue

func (expression Expression) GetValue() string

type From

type From struct {
	Type   string
	Name   interface{}
	Alias  string
	Offset int
	SQL    string
}

func (From) IsEmpty

func (from From) IsEmpty() bool

type Grammar

type Grammar interface {
	NewWith(db *sqlx.DB, config *Config, option *Option) (Grammar, error)
	NewWithRead(write *sqlx.DB, writeConfig *Config, read *sqlx.DB, readConfig *Config, option *Option) (Grammar, error)
	Wrap(value interface{}) string
	WrapTable(value interface{}) string
	OnConnected() error
	GetVersion() (*Version, error)
	GetDatabase() string
	GetSchema() string
	GetOperators() []string
	GetTables() ([]string, error)
	TableExists(name string) (bool, error)
	GetTable(name string) (*Table, error)
	CreateTable(table *Table) error
	AlterTable(table *Table) error
	DropTable(name string) error
	DropTableIfExists(name string) error
	RenameTable(old string, new string) error
	GetColumnListing(dbName string, tableName string) ([]*Column, error)
	CompileInsert(query *Query, columns []interface{}, values [][]interface{}) (string, []interface{})
	CompileInsertOrIgnore(query *Query, columns []interface{}, values [][]interface{}) (string, []interface{})
	CompileInsertGetID(query *Query, columns []interface{}, values [][]interface{}, sequence string) (string, []interface{})
	CompileInsertUsing(query *Query, columns []interface{}, sql string) string
	CompileUpsert(query *Query, columns []interface{}, values [][]interface{}, uniqueBy []interface{}, updateValues interface{}) (string, []interface{})
	CompileUpdate(query *Query, values map[string]interface{}) (string, []interface{})
	CompileDelete(query *Query) (string, []interface{})
	CompileTruncate(query *Query) ([]string, [][]interface{})
	CompileSelect(query *Query) string
	CompileSelectOffset(query *Query, offset *int) string
	CompileExists(query *Query) string
	ProcessInsertGetID(sql string, bindings []interface{}, sequence string) (int64, error)
}

type Having

type Having struct {
	Type     string
	Column   interface{}
	Operator string
	Value    interface{}
	Boolean  string
	Offset   int
	Values   []interface{}
	Not      bool
	SQL      string
}

type Index

type Index struct {
	DBName       string  `db:"db_name"`
	TableName    string  `db:"table_name"`
	ColumnName   string  `db:"column_name"`
	Name         string  `db:"index_name"`
	SEQ          int     `db:"seq_in_index"`
	SeqColumn    int     `db:"seq_in_column"`
	Collation    string  `db:"collation"`
	Nullable     bool    `db:"nullable"`
	Unique       bool    `db:"unique"`
	Primary      bool    `db:"primary"`
	SubPart      int     `db:"sub_part"`
	Type         string  `db:"type"`
	IndexType    string  `db:"index_type"`
	Comment      *string `db:"comment"`
	IndexComment *string `db:"index_comment"`
	Table        *Table
	Columns      []*Column
}

func (*Index) AddColumn

func (index *Index) AddColumn(column *Column)

type Join

type Join struct {
	Type   string
	Name   interface{}
	Query  *Query
	Alias  string
	SQL    interface{}
	Offset int
}

type Name

type Name struct {
	Prefix string
	Name   string
	Alias  string
}

func NewName

func NewName(fullname string, prefix ...string) Name

func (Name) As

func (name Name) As() string

func (Name) Fullname

func (name Name) Fullname() string

type Option

type Option struct {
	Prefix    string `json:"prefix"`
	Collation string `json:"collation"`
	Charset   string `json:"charset"`
}

type Order

type Order struct {
	Type      string
	Column    interface{}
	Direction string
	Offset    int
	SQL       string
}

type Primary

type Primary struct {
	DBName    string `db:"db_name"`
	TableName string `db:"table_name"`
	Name      string `db:"primary_name"`
	Table     *Table
	Columns   []*Column
}

type Query

type Query struct {
	UseWriteConnection bool
	Lock               interface{}
	From               From
	Columns            []interface{}
	Aggregate          Aggregate
	Wheres             []Where
	Joins              []Join
	Unions             []Union
	UnionLimit         int
	UnionOffset        int
	UnionOrders        []Order
	Orders             []Order
	Limit              int
	Offset             int
	Groups             []interface{}
	Havings            []Having
	Bindings           map[string][]interface{}
	Distinct           bool
	DistinctColumns    []interface{}
	IsJoinClause       bool
	BindingOffset      int
	SQL                string
}

func NewQuery

func NewQuery() *Query

func (*Query) AddBinding

func (query *Query) AddBinding(typ string, value interface{})

func (*Query) AddColumn

func (query *Query) AddColumn(column interface{}) *Query

func (*Query) Clone

func (query *Query) Clone() *Query

func (*Query) CopyAggregate

func (query *Query) CopyAggregate() Aggregate

func (*Query) CopyBindings

func (query *Query) CopyBindings() map[string][]interface{}

CopyBindings copy Bindings

func (*Query) CopyColumns

func (query *Query) CopyColumns() []interface{}

func (*Query) CopyDistinctColumns

func (query *Query) CopyDistinctColumns() []interface{}

func (*Query) CopyFrom

func (query *Query) CopyFrom() From

func (*Query) CopyGroups

func (query *Query) CopyGroups() []interface{}

func (*Query) CopyHavings

func (query *Query) CopyHavings() []Having

func (*Query) CopyJoins

func (query *Query) CopyJoins() []Join

func (*Query) CopyLock

func (query *Query) CopyLock() interface{}

func (*Query) CopyOrders

func (query *Query) CopyOrders() []Order

func (*Query) CopyUnionOrders

func (query *Query) CopyUnionOrders() []Order

func (*Query) CopyUnions

func (query *Query) CopyUnions() []Union

func (*Query) CopyWheres

func (query *Query) CopyWheres() []Where

func (*Query) GetBindings

func (query *Query) GetBindings(key ...string) []interface{}

type Quoter

type Quoter interface {
	Bind(db *sqlx.DB, prefix string, dbRead ...*sqlx.DB) Quoter
	ID(value string) string
	VAL(value interface{}) string
	Wrap(value interface{}) string
	WrapTable(value interface{}) string
	WrapUnion(sql string) string
	IsExpression(value interface{}) bool
	Parameter(value interface{}, num int) string
	Parameterize(values []interface{}, offset int) string
	Columnize(columns []interface{}) string
}

type Select

type Select struct {
	Type   string
	Name   interface{}
	Alias  string
	Offset int
	SQL    string
}

type Table

type Table struct {
	DBName        string    `db:"db_name"`
	SchemaName    string    `db:"schema_name"`
	TableName     string    `db:"table_name"`
	Comment       string    `db:"table_comment"`
	Type          string    `db:"table_type"`
	Engine        string    `db:"engine"`
	CreateTime    time.Time `db:"create_time"`
	CreateOptions string    `db:"create_options"`
	Collation     string    `db:"collation"`
	Charset       string    `db:"charset"`
	Rows          int       `db:"table_rows"`
	RowLength     int       `db:"avg_row_length"`
	IndexLength   int       `db:"index_length"`
	AutoIncrement int       `db:"auto_increment"`
	Primary       *Primary
	ColumnMap     map[string]*Column
	IndexMap      map[string]*Index
	Columns       []*Column
	Indexes       []*Index
	Commands      []*Command
}

func NewTable

func NewTable(name string, schemaName string, dbName string) *Table

func (*Table) AddCommand

func (table *Table) AddCommand(name string, success func(), fail func(), params ...interface{})

func (*Table) GetColumn

func (table *Table) GetColumn(name string) *Column

func (*Table) GetIndex

func (table *Table) GetIndex(name string) *Index

func (*Table) GetName

func (table *Table) GetName() string

func (*Table) GetPrimary

func (table *Table) GetPrimary(name string, columns ...*Column) *Primary

func (*Table) HasColumn

func (table *Table) HasColumn(name string) bool

func (*Table) HasIndex

func (table *Table) HasIndex(name string) bool

func (*Table) NewColumn

func (table *Table) NewColumn(name string) *Column

func (*Table) NewIndex

func (table *Table) NewIndex(name string, columns ...*Column) *Index

func (*Table) NewPrimary

func (table *Table) NewPrimary(name string, columns ...*Column) *Primary

func (*Table) PushColumn

func (table *Table) PushColumn(column *Column) *Table

func (*Table) PushIndex

func (table *Table) PushIndex(index *Index) *Table

type Union

type Union struct {
	All   bool
	Query *Query
}

type Version

type Version struct {
	Driver string
	semver.Version
}

type Where

type Where struct {
	Type     string
	Column   interface{}
	First    interface{}
	Second   interface{}
	SQL      string
	Operator string
	Boolean  string
	Wheres   []Where
	Query    *Query
	Value    interface{}
	Values   []interface{}
	ValuesIn interface{}
	Not      bool
	Offset   int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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