datasrc

package
v0.0.0-...-f860bb7 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConnectTimeout is the database connection timeout.
	ConnectTimeout = time.Second * 5
)

Functions

func RegistDriver

func RegistDriver(driverName string, driver Driver)

RegistDriver regist a driver.

Types

type Column

type Column struct {

	// Name is name of the result column.
	Name string

	// ScanType is the go type suitable for scanning into.
	ScanType reflect.Type

	// DatabaseTypeName is the database system name of the column type. (e.g. "VARCHAR", "INT")
	DatabaseTypeName string

	// Nullable is valid only when HasNullable is true.
	HasNullable bool

	// Nullable is true if this column can have NULL value.
	Nullable bool

	// Length is valid only HasLength is true
	HasLength bool

	// Length returns the column type length for variable length column types.
	Length int64

	// Precision and Scale is valid only when HasPrecisionScale is true.
	HasPrecisionScale bool

	// Column precision.
	Precision int64

	// Column scale.
	Scale int64

	// DataType is a 'translated' driver-specific type identifier (ignore nullable), such as:
	// - uint24
	// - json
	// - time
	// It is used in scan type mapping only, thus can be any valid identifier, no need to be a real type name.
	DataType string
}

Column represents a query result column.

func NewColumn

func NewColumn(col *sql.ColumnType, dataType string) *Column

NewColumn extract information from sql.Column and returns Column.

type Driver

type Driver interface {
	// LoadQueryResultColumns returns result columns of a query.
	LoadQueryResultColumns(conn *sql.Conn, query string, args ...interface{}) (columns []*Column, err error)

	// LoadTableNames returns all table names in current database.
	LoadTableNames(conn *sql.Conn) (tableNames []string, err error)

	// LoadTableColumns returns columns of a given table.
	LoadTableColumns(conn *sql.Conn, tableName string) (tableColumns []*TableColumn, err error)

	// LoadIndexNames returns all index name for a given table.
	LoadIndexNames(conn *sql.Conn, tableName string) (indexNames []string, err error)

	// LoadIndex returns information of a given index.
	LoadIndex(conn *sql.Conn, tableName, indexName string) (columnNames []string, isPrimary bool, isUnique bool, err error)

	// LoadFKNames returns all foreign key constraint names for a given table.
	LoadFKNames(conn *sql.Conn, tableName string) (fkNames []string, err error)

	// LoadFK returns information of a given foreign key constraint.
	LoadFK(conn *sql.Conn, tableName, fkName string) (columnNames []string, refTableName string, refColumnNames []string, err error)

	// DataTypes returns full list of driver-specific type identifiers used in Column.DataType.
	DataTypes() []string

	// Quote returns the quoted identifier.
	Quote(identifier string) string
}

Driver is the low level interface of loader talking to different databases.

NOTE: Use sql.Conn instead of sql.DB to make sure only one database connection is using.

func GetDriver

func GetDriver(driverName string) Driver

GetDriver get a Driver by its name.

type DriverWithAutoInc

type DriverWithAutoInc interface {
	Driver

	// LoadAutoIncColumn returns the 'auto increament' column's name for a given table or "" if not found.
	LoadAutoIncColumn(conn *sql.Conn, tableName string) (columnName string, err error)
}

DriverWithAutoInc is Driver having single auto increment column support (e.g. MySQL)

type Loader

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

Loader is used to load information from a database.

func NewLoader

func NewLoader(driverName, dataSourceName string) (*Loader, error)

NewLoader creates a new Loader.

func (*Loader) Close

func (loader *Loader) Close()

Close release resource.

func (*Loader) Conn

func (loader *Loader) Conn() *sql.Conn

Conn returns a single connection object.

func (*Loader) ConnPool

func (loader *Loader) ConnPool() *sql.DB

ConnPool returns the connection pool object.

func (*Loader) DataSourceName

func (loader *Loader) DataSourceName() string

DataSourceName returns the dsn.

func (*Loader) DataTypes

func (loader *Loader) DataTypes() []string

DataTypes returns full list of driver-specific type identifiers used in Column.DataType.

func (*Loader) DriverName

func (loader *Loader) DriverName() string

DriverName returns the driver's name.

func (*Loader) LoadAutoIncColumn

func (loader *Loader) LoadAutoIncColumn(tableName string) (columnName string, err error)

LoadAutoIncColumn returns the 'auto increament' column's name for a given table or "" if not found.

func (*Loader) LoadFK

func (loader *Loader) LoadFK(tableName, fkName string) (columnNames []string, refTableName string, refColumnNames []string, err error)

LoadFK returns information of a given foreign key constraint.

func (*Loader) LoadFKNames

func (loader *Loader) LoadFKNames(tableName string) (fkNames []string, err error)

LoadFKNames returns all foreign key constraint names for a given table.

func (*Loader) LoadIndex

func (loader *Loader) LoadIndex(tableName, indexName string) (columnNames []string, isPrimary bool, isUnique bool, err error)

LoadIndex returns information of a given index.

func (*Loader) LoadIndexNames

func (loader *Loader) LoadIndexNames(tableName string) (indexNames []string, err error)

LoadIndexNames returns all index name for a given table.

func (*Loader) LoadQueryResultColumns

func (loader *Loader) LoadQueryResultColumns(query string, args ...interface{}) (columns []*Column, err error)

LoadQueryResultColumns returns result columns of a query.

func (*Loader) LoadTableColumns

func (loader *Loader) LoadTableColumns(tableName string) (columns []*TableColumn, err error)

LoadTableColumns returns columns of a given table.

func (*Loader) LoadTableNames

func (loader *Loader) LoadTableNames() (tableNames []string, err error)

LoadTableNames returns all table names in current database.

func (*Loader) Quote

func (loader *Loader) Quote(identifier string) string

Quote returns the quoted identifier.

type TableColumn

type TableColumn struct {
	// Basic column information.
	Column

	// Pos is the position of the column in table.
	Pos int

	// DefaultValue is the default value of the table column.
	DefaultValue sql.NullString
}

TableColumn represents a table column.

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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