sqlx

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: MIT Imports: 14 Imported by: 0

README

Sqlx

GoDoc Widget Build Status codecov Go Report Card

Sql helpers just for mysql and mysql-compatibility db.

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 Scan

func Scan(rows *sql.Rows, v interface{}) error

func SyncEnum

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

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() *datatypes.ColumnType

type DB

type DB struct {
	SqlExecutor
}

func MustOpen

func MustOpen(driverName string, dataSourceName string) *DB

func Open

func Open(driverName string, dataSourceName string) (*DB, error)

func (*DB) Begin

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

func (*DB) Commit

func (d *DB) Commit() error

func (*DB) Exec

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

func (*DB) ExecExpr

func (d *DB) ExecExpr(expr builder.SqlExpr) (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) QueryExpr

func (d *DB) QueryExpr(expr builder.SqlExpr) (*sql.Rows, error)

func (*DB) QueryExprAndScan

func (d *DB) QueryExprAndScan(expr builder.SqlExpr, v interface{}) 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) Assignments

func (database *Database) Assignments(model builder.Model, excludes ...string) builder.Assignments

func (*Database) MigrateTo

func (database *Database) MigrateTo(db *DB, opts MigrationOptions) error

func (*Database) Register

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

func (Database) T

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

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 MigrationOptions

type MigrationOptions struct {
	DropColumn bool
	DryRun     bool
}

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() builder.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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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