sqlx

package
v0.0.0-...-61829c1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DuplicateEntryErrNumber uint16 = 1062
View Source
var ErrNotDB = errors.New("db is not *sql.DB")
View Source
var ErrNotTx = errors.New("db is not *sql.Tx")
View Source
var SchemaDatabase = NewDatabase("INFORMATION_SCHEMA")

Functions

func DBErr

func DBErr(err error) *dbErr

func FieldValuesFromStructBy

func FieldValuesFromStructBy(structValue interface{}, fieldNames []string) (fieldValues builder.FieldValues)

func FieldValuesFromStructByNonZero

func FieldValuesFromStructByNonZero(structValue interface{}, excludes ...string) (fieldValues builder.FieldValues)

func ForEachStructField

func ForEachStructField(structType reflect.Type, fn func(structField reflect.StructField, columnName string))

func ForEachStructFieldValue

func ForEachStructFieldValue(rv reflect.Value, fn func(structFieldValue reflect.Value, structField reflect.StructField, columnName string))

func ScanDefToTable

func ScanDefToTable(rv reflect.Value, table *builder.Table)

Types

type ColumnSchema

type ColumnSchema struct {
	TABLE_SCHEMA             string         `db:"TABLE_SCHEMA" sql:"varchar(64) NOT NULL DEFAULT ''"`
	TABLE_NAME               string         `db:"TABLE_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
	COLUMN_NAME              string         `db:"COLUMN_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
	ORDINAL_POSITION         int32          `db:"ORDINAL_POSITION" sql:"bigint(21) unsigned NOT NULL DEFAULT '0'"`
	COLUMN_DEFAULT           sql.NullString `db:"COLUMN_DEFAULT" sql:"longtext"`
	IS_NULLABLE              string         `db:"IS_NULLABLE" sql:"varchar(3) NOT NULL DEFAULT ''"`
	DATA_TYPE                string         `db:"DATA_TYPE" sql:"varchar(64) NOT NULL DEFAULT ''"`
	CHARACTER_MAXIMUM_LENGTH sql.NullInt64  `db:"CHARACTER_MAXIMUM_LENGTH" sql:"bigint(21) unsigned DEFAULT NULL"`
	CHARACTER_OCTET_LENGTH   sql.NullInt64  `db:"CHARACTER_OCTET_LENGTH" sql:"bigint(21) unsigned DEFAULT NULL"`
	NUMERIC_PRECISION        sql.NullInt64  `db:"NUMERIC_PRECISION" sql:"bigint(21) unsigned DEFAULT NULL"`
	NUMERIC_SCALE            sql.NullInt64  `db:"NUMERIC_SCALE" sql:"bigint(21) unsigned DEFAULT NULL"`
	DATETIME_PRECISION       sql.NullInt64  `db:"DATETIME_PRECISION" sql:"bigint(21) unsigned DEFAULT NULL"`
	CHARACTER_SET_NAME       sql.NullString `db:"CHARACTER_SET_NAME" sql:"varchar(32) DEFAULT NULL"`
	COLLATION_NAME           sql.NullString `db:"COLLATION_NAME" sql:"varchar(32) DEFAULT NULL"`
	COLUMN_TYPE              string         `db:"COLUMN_TYPE" sql:"longtext NOT NULL"`
	COLUMN_KEY               string         `db:"COLUMN_KEY" sql:"varchar(3) NOT NULL DEFAULT ''"`
	EXTRA                    string         `db:"EXTRA" sql:"varchar(30) NOT NULL DEFAULT ''"`
	PRIVILEGES               string         `db:"PRIVILEGES" sql:"varchar(80) NOT NULL DEFAULT ''"`
	COLUMN_COMMENT           string         `db:"COLUMN_COMMENT" sql:"varchar(1024) NOT NULL DEFAULT ''"`
}

func (ColumnSchema) TableName

func (columnSchema ColumnSchema) TableName() string

func (ColumnSchema) ToColumnType

func (columnSchema ColumnSchema) ToColumnType() *data_type.ColumnType

type DB

type DB struct {
	SqlExecutor
}

func MustOpen

func MustOpen(driverName string, dataSourceName string, openFunc func(string, string) (*sql.DB, error)) *DB

func Open

func Open(driverName string, dataSourceName string, openFunc func(string, string) (*sql.DB, error)) (*DB, error)

func (*DB) Begin

func (d *DB) Begin() (*DB, error)

func (*DB) Commit

func (d *DB) Commit() error

func (*DB) Do

func (d *DB) Do(stmt builder.Statement) (result *Result)

func (*DB) Exec

func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DB) IsTx

func (d *DB) IsTx() bool

func (*DB) Query

func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*DB) Rollback

func (d *DB) Rollback() error

func (*DB) SetConnMaxLifetime

func (d *DB) SetConnMaxLifetime(t time.Duration)

func (*DB) SetMaxIdleConns

func (d *DB) SetMaxIdleConns(n int)

func (*DB) SetMaxOpenConns

func (d *DB) SetMaxOpenConns(n int)

type Database

type Database struct {
	*builder.Database
}

func DBFromInformationSchema

func DBFromInformationSchema(db *DB, dbName string, tableNames ...string) *Database

func NewDatabase

func NewDatabase(name string) *Database

func NewFeatureDatabase

func NewFeatureDatabase(name string) *Database

func (*Database) Insert

func (database *Database) Insert(model Model) *builder.StmtInsert

func (*Database) MigrateTo

func (database *Database) MigrateTo(db *DB, dryRun bool) error

func (*Database) MustMigrateTo

func (database *Database) MustMigrateTo(db *DB, dryRun bool)

func (*Database) Register

func (database *Database) Register(model Model) *builder.Table

func (*Database) SyncEnum

func (database *Database) SyncEnum(db *DB) error

func (Database) T

func (database Database) T(model Model) *builder.Table

func (*Database) Update

func (database *Database) Update(model Model, zeroFields ...string) *builder.StmtUpdate

type EnumTypeDescriber

type EnumTypeDescriber interface {
	EnumType() string
	Enums() map[int][]string
}

type FieldNames

type FieldNames []string

func (FieldNames) Map

func (fieldNames FieldNames) Map() map[string]bool

type IndexDeclarer

type IndexDeclarer func() (indexName string, fieldNames FieldNames)

type IndexSchema

type IndexSchema struct {
	TABLE_SCHEMA  string         `db:"TABLE_SCHEMA" sql:"varchar(64) NOT NULL DEFAULT ''"`
	TABLE_NAME    string         `db:"TABLE_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
	NON_UNIQUE    int32          `db:"NON_UNIQUE" sql:"bigint(1) NOT NULL DEFAULT '0'"`
	INDEX_SCHEMA  string         `db:"INDEX_SCHEMA" sql:"varchar(64) NOT NULL DEFAULT ''"`
	INDEX_NAME    string         `db:"INDEX_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
	SEQ_IN_INDEX  int32          `db:"SEQ_IN_INDEX" sql:"bigint(2) NOT NULL DEFAULT '0'"`
	COLUMN_NAME   string         `db:"COLUMN_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
	COLLATION     sql.NullString `db:"COLLATION" sql:"varchar(1) DEFAULT NULL"`
	CARDINALITY   sql.NullInt64  `db:"CARDINALITY" sql:"bigint(21) DEFAULT NULL"`
	SUB_PART      sql.NullInt64  `db:"SUB_PART" sql:"bigint(3) DEFAULT NULL"`
	PACKED        sql.NullString `db:"PACKED" sql:"varchar(10) DEFAULT NULL"`
	NULLABLE      string         `db:"NULLABLE" sql:"varchar(3) NOT NULL DEFAULT ''"`
	INDEX_TYPE    string         `db:"INDEX_TYPE" sql:"varchar(16) NOT NULL DEFAULT ''"`
	COMMENT       string         `db:"COMMENT" sql:"varchar(16) DEFAULT NULL"`
	INDEX_COMMENT string         `db:"INDEX_COMMENT" sql:"varchar(1024) NOT NULL DEFAULT ''"`
}

func (IndexSchema) TableName

func (indexSchema IndexSchema) TableName() string

type Indexes

type Indexes map[string]FieldNames

type Model

type Model interface {
	TableName() string
}

type Result

type Result struct {
	*sql.Rows
	sql.Result
	// contains filtered or unexported fields
}

func Do

func Do(db *DB, stmt builder.Statement) (result *Result)

func (*Result) Err

func (r *Result) Err() error

func (*Result) Scan

func (r *Result) Scan(v interface{}) *Result

type Schema

type Schema struct {
	SCHEMA_NAME string `db:"SCHEMA_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
}

func (Schema) TableName

func (schema Schema) TableName() string

type SqlError

type SqlError struct {
	Type sqlErrType
	Msg  string
}

func NewSqlError

func NewSqlError(tpe sqlErrType, msg string) *SqlError

func (*SqlError) Error

func (e *SqlError) Error() string

type SqlExecutor

type SqlExecutor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

type SqlMetaEnum

type SqlMetaEnum struct {
	TName string `db:"F_table_name" sql:"varchar(64) NOT NULL"`
	CName string `db:"F_column_name" sql:"varchar(64) NOT NULL"`
	Value int    `db:"F_value" sql:"int NOT NULL"`
	Type  string `db:"F_type" sql:"varchar(255) NOT NULL"`
	Key   string `db:"F_key"  sql:"varchar(255) NOT NULL"`
	Label string `db:"F_label" sql:"varchar(255) NOT NULL"`
}

func (*SqlMetaEnum) TableName

func (*SqlMetaEnum) TableName() string

func (*SqlMetaEnum) UniqueIndexes

func (*SqlMetaEnum) UniqueIndexes() Indexes

type TableSchema

type TableSchema struct {
	TABLE_SCHEMA    string         `db:"TABLE_SCHEMA" sql:"varchar(64) NOT NULL DEFAULT ''"`
	TABLE_NAME      string         `db:"TABLE_NAME" sql:"varchar(64) NOT NULL DEFAULT ''"`
	TABLE_TYPE      string         `db:"TABLE_TYPE" sql:"varchar(64) NOT NULL DEFAULT ''"`
	ENGINE          sql.NullString `db:"ENGINE" sql:"varchar(64) DEFAULT NULL"`
	VERSION         sql.NullInt64  `db:"VERSION" sql:"bigint(21) unsigned DEFAULT NULL"`
	ROW_FORMAT      sql.NullString `db:"ROW_FORMAT" sql:"varchar(10) DEFAULT NULL"`
	TABLE_ROWS      sql.NullInt64  `db:"TABLE_ROWS" sql:"bigint(21) unsigned DEFAULT NULL"`
	AVG_ROW_LENGTH  sql.NullInt64  `db:"AVG_ROW_LENGTH" sql:"bigint(21) unsigned DEFAULT NULL"`
	DATA_LENGTH     sql.NullInt64  `db:"DATA_LENGTH" sql:"bigint(21) unsigned DEFAULT NULL"`
	MAX_DATA_LENGTH sql.NullInt64  `db:"MAX_DATA_LENGTH" sql:"bigint(21) unsigned DEFAULT NULL"`
	INDEX_LENGTH    sql.NullInt64  `db:"INDEX_LENGTH" sql:"bigint(21) unsigned DEFAULT NULL"`
	DATA_FREE       sql.NullInt64  `db:"DATA_FREE" sql:"bigint(21) unsigned DEFAULT NULL"`
	AUTO_INCREMENT  sql.NullString `db:"AUTO_INCREMENT" sql:"bigint(21) unsigned DEFAULT NULL"`
	CREATE_TIME     time.Time      `db:"CREATE_TIME" sql:"datetime DEFAULT NULL"`
	UPDATE_TIME     time.Time      `db:"UPDATE_TIME" sql:"datetime DEFAULT NULL"`
	CHECK_TIME      time.Time      `db:"CHECK_TIME" sql:"datetime DEFAULT NULL"`
	TABLE_COLLATION sql.NullString `db:"TABLE_COLLATION" sql:"varchar(32) DEFAULT NULL"`
	CHECKSUM        sql.NullInt64  `db:"CHECKSUM" sql:"bigint(21) unsigned DEFAULT NULL"`
	CREATE_OPTIONS  sql.NullString `db:"CREATE_OPTIONS" sql:"varchar(255) DEFAULT NULL"`
	TABLE_COMMENT   string         `db:"TABLE_COMMENT" sql:"varchar(2048) NOT NULL DEFAULT ''"`
}

func (TableSchema) TableName

func (tableSchema TableSchema) TableName() string

type Task

type Task func(db *DB) error

func (Task) Run

func (task Task) Run(db *DB) (err error)

type Tasks

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

func NewTasks

func NewTasks(db *DB) *Tasks

func (*Tasks) Do

func (tasks *Tasks) Do() (err error)

func (Tasks) With

func (tasks Tasks) With(task ...Task) *Tasks

type Time

type Time interface {
	SetNow()
	IsZero() bool
}

type WithComments

type WithComments interface {
	Comments() map[string]string
}

type WithIndexes

type WithIndexes interface {
	Indexes() Indexes
}

type WithPrimaryKey

type WithPrimaryKey interface {
	PrimaryKey() FieldNames
}

type WithUniqueIndexes

type WithUniqueIndexes interface {
	UniqueIndexes() Indexes
}

type ZeroSetter

type ZeroSetter interface {
	SetToZero()
}

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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