mydb

package
v0.0.0-...-7c1eb0e Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = errors.New("sql: no rows in result set")

Functions

func CheckDatabaseExist

func CheckDatabaseExist(db *XDb, name string, driver string) bool

func CheckRecordExist

func CheckRecordExist(db *XDb, sql string, driver string) bool

func CheckRecordExistByTx

func CheckRecordExistByTx(db *MyTx, sql string, driver string) bool

func CheckSqliteTableExist

func CheckSqliteTableExist(db *XDb, tableName string) bool

func CheckTableExist

func CheckTableExist(db *XDb, name string, driver string) bool

func CreateTableFromStruct

func CreateTableFromStruct(dbType string, tbName string, engine string, inf interface{}, args ...string) (string, error)

func GetDBFieldType

func GetDBFieldType(row *MyRows) (map[string]*MyFieldType, bool)

func MysqlCreateTableFromStruct

func MysqlCreateTableFromStruct(tbName string, engine string, inf interface{}, args ...string) (string, error)

func MysqlFillStruct

func MysqlFillStruct(rows *MyRows, inf interface{}) error

func MysqlInsertTableFromStruct

func MysqlInsertTableFromStruct(tbName string, inf interface{}, skip map[string]string) (string, error)

func MysqlInsertTableFromStructByValues

func MysqlInsertTableFromStructByValues(tbName string, inf interface{}, skip map[string]string) (string, error)

func MysqlUpdateTableFromStruct

func MysqlUpdateTableFromStruct(tbName string, inf interface{}, where string, skip map[string]string) (string, error)

func RowToModel

func RowToModel(row IGetData, m interface{}) error

func SetFieldValue

func SetFieldValue(row IGetData, tabinfo *TableInfo) (err error)

取数据赋给对应的struct里的字段

func SetValue

func SetValue(row IGetData, model interface{}) (err error)

设置model的值

func SqlLiteCreateTableFromStruct

func SqlLiteCreateTableFromStruct(tbName string, engine string, inf interface{}, args ...string) (string, []string, error)

Types

type DataRow

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

func (*DataRow) Bool

func (me *DataRow) Bool(strFieldName string) bool

取bool类型的字段

func (*DataRow) Bytes

func (me *DataRow) Bytes(strFieldName string) []byte

取[]byte类型的字段

func (*DataRow) Float

func (me *DataRow) Float(strFieldName string) float32

取float32类型的字段

func (*DataRow) Float32

func (me *DataRow) Float32(strFieldName string) float32

取float32类型的字段

func (*DataRow) Float64

func (me *DataRow) Float64(strFieldName string) float64

取float64类型的字段

func (*DataRow) GetValue

func (me *DataRow) GetValue(name string, value interface{}) error

GetValue 根据字段名来取字段的值 name:字段名,区分大小写 value:用来接收字段值的变量,需传变量的地址,如&a

func (*DataRow) Int

func (me *DataRow) Int(strFieldName string) int

取int类型的字段

func (*DataRow) Int16

func (me *DataRow) Int16(strFieldName string) int16

取int16类型的字段

func (*DataRow) Int32

func (me *DataRow) Int32(strFieldName string) int32

取int32类型的字段

func (*DataRow) Int64

func (me *DataRow) Int64(strFieldName string) int64

取int64类型的字段

func (*DataRow) Int8

func (me *DataRow) Int8(strFieldName string) int8

取int8类型的字段

func (*DataRow) String

func (me *DataRow) String(strFieldName string) string

取string类型的字段

func (*DataRow) Time

func (me *DataRow) Time(strFieldName string) time.Time

取Time类型的字段

func (*DataRow) Uint

func (me *DataRow) Uint(strFieldName string) uint

取uint类型的字段

func (*DataRow) Uint16

func (me *DataRow) Uint16(strFieldName string) uint16

取uint16类型的字段

func (*DataRow) Uint32

func (me *DataRow) Uint32(strFieldName string) uint32

取uint32类型的字段

func (*DataRow) Uint64

func (me *DataRow) Uint64(strFieldName string) uint64

取uint64类型的字段

func (*DataRow) Uint8

func (me *DataRow) Uint8(strFieldName string) uint8

取uint8类型的字段

type FieldInfo

type FieldInfo struct {
	Name           string //字段名
	IsPrimaryKey   bool   //是否主键
	IsAutoGenerate bool   //是否自动生成(增长)
	Value          reflect.Value
}

type IGetData

type IGetData interface {
	GetValue(name string, value interface{}) error
}

type MyFieldType

type MyFieldType struct {
	Name       string
	Length     int
	FType      string
	FormatType string
}

type MyRow

type MyRow struct {
	IsHasRows bool //true表示有数据,false没数据
	// contains filtered or unexported fields
}

func (*MyRow) Bool

func (me *MyRow) Bool(strFieldName string) bool

取bool类型的字段

func (*MyRow) Bytes

func (me *MyRow) Bytes(strFieldName string) []byte

取[]byte类型的字段

func (*MyRow) Float

func (me *MyRow) Float(strFieldName string) float32

取float32类型的字段

func (*MyRow) Float32

func (me *MyRow) Float32(strFieldName string) float32

取float32类型的字段

func (*MyRow) Float64

func (me *MyRow) Float64(strFieldName string) float64

取float64类型的字段

func (*MyRow) GetValue

func (me *MyRow) GetValue(name string, value interface{}) error

根据字段名来取字段的值 name:字段名,区分大小写 value:用来接收字段值的变量,需传变量的地址,如&a

func (*MyRow) Int

func (me *MyRow) Int(strFieldName string) int

取int类型的字段

func (*MyRow) Int16

func (me *MyRow) Int16(strFieldName string) int16

取int16类型的字段

func (*MyRow) Int32

func (me *MyRow) Int32(strFieldName string) int32

取int32类型的字段

func (*MyRow) Int64

func (me *MyRow) Int64(strFieldName string) int64

取int64类型的字段

func (*MyRow) Int8

func (me *MyRow) Int8(strFieldName string) int8

取int8类型的字段

func (*MyRow) Scan

func (me *MyRow) Scan(dest ...interface{}) error

func (*MyRow) String

func (me *MyRow) String(strFieldName string) string

取string类型的字段

func (*MyRow) Time

func (me *MyRow) Time(strFieldName string) time.Time

取Time类型的字段

func (*MyRow) Uint

func (me *MyRow) Uint(strFieldName string) uint

取uint类型的字段

func (*MyRow) Uint16

func (me *MyRow) Uint16(strFieldName string) uint16

取uint16类型的字段

func (*MyRow) Uint32

func (me *MyRow) Uint32(strFieldName string) uint32

取uint32类型的字段

func (*MyRow) Uint64

func (me *MyRow) Uint64(strFieldName string) uint64

取uint64类型的字段

func (*MyRow) Uint8

func (me *MyRow) Uint8(strFieldName string) uint8

取uint8类型的字段

type MyRows

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

func (*MyRows) Bool

func (me *MyRows) Bool(strFieldName string) bool

取bool类型的字段

func (*MyRows) Bytes

func (me *MyRows) Bytes(strFieldName string) []byte

取[]byte类型的字段

func (*MyRows) Close

func (me *MyRows) Close() error

func (*MyRows) Float

func (me *MyRows) Float(strFieldName string) float32

取float32类型的字段

func (*MyRows) Float32

func (me *MyRows) Float32(strFieldName string) float32

取float32类型的字段

func (*MyRows) Float64

func (me *MyRows) Float64(strFieldName string) float64

取float64类型的字段

func (*MyRows) GetCreateTime

func (me *MyRows) GetCreateTime() int64

func (*MyRows) GetFields

func (me *MyRows) GetFields() []string

func (*MyRows) GetOrgValue

func (me *MyRows) GetOrgValue(name string) (interface{}, bool)

func (*MyRows) GetValue

func (me *MyRows) GetValue(name string, value interface{}) error

根据字段名来取字段的值 name:字段名,区分大小写 value:用来接收字段值的变量,需传变量的地址,如&a

func (*MyRows) GetValueByIndex

func (me *MyRows) GetValueByIndex(index int, value interface{}) error

func (*MyRows) GetValues

func (me *MyRows) GetValues() map[string]interface{}

func (*MyRows) Int

func (me *MyRows) Int(strFieldName string) int

取int类型的字段

func (*MyRows) Int16

func (me *MyRows) Int16(strFieldName string) int16

取int16类型的字段

func (*MyRows) Int32

func (me *MyRows) Int32(strFieldName string) int32

取int32类型的字段

func (*MyRows) Int64

func (me *MyRows) Int64(strFieldName string) int64

取int64类型的字段

func (*MyRows) Int8

func (me *MyRows) Int8(strFieldName string) int8

取int8类型的字段

func (*MyRows) IsNULL

func (me *MyRows) IsNULL(name string) bool

func (*MyRows) Next

func (me *MyRows) Next() bool

func (*MyRows) SaveFields

func (me *MyRows) SaveFields()

func (*MyRows) Scan

func (me *MyRows) Scan(dest ...interface{}) error

func (*MyRows) SetNoCase

func (me *MyRows) SetNoCase(enable bool)

func (*MyRows) String

func (me *MyRows) String(strFieldName string) string

取string类型的字段

func (*MyRows) Time

func (me *MyRows) Time(strFieldName string) time.Time

取Time类型的字段

func (*MyRows) Uint

func (me *MyRows) Uint(strFieldName string) uint

取uint类型的字段

func (*MyRows) Uint16

func (me *MyRows) Uint16(strFieldName string) uint16

取uint16类型的字段

func (*MyRows) Uint32

func (me *MyRows) Uint32(strFieldName string) uint32

取uint32类型的字段

func (*MyRows) Uint64

func (me *MyRows) Uint64(strFieldName string) uint64

取uint64类型的字段

func (*MyRows) Uint8

func (me *MyRows) Uint8(strFieldName string) uint8

取uint8类型的字段

type MyStmt

type MyStmt struct {
	*sql.Stmt
	// contains filtered or unexported fields
}

func (*MyStmt) Query

func (me *MyStmt) Query(args ...interface{}) (*MyRows, error)

func (*MyStmt) QueryRow

func (me *MyStmt) QueryRow(args ...interface{}) (*MyRow, error)

type MyTx

type MyTx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

func (*MyTx) DBQueryAll

func (me *MyTx) DBQueryAll(sql string, args ...interface{}) ([]map[string]interface{}, error)

func (*MyTx) DBQueryAllField

func (me *MyTx) DBQueryAllField(sql string, args ...interface{}) ([]string, []map[string]interface{}, error)

func (*MyTx) Prepare

func (me *MyTx) Prepare(query string) (*MyStmt, error)

func (*MyTx) Query

func (me *MyTx) Query(query string, args ...interface{}) (*MyRows, error)

func (*MyTx) QueryRow

func (me *MyTx) QueryRow(query string, args ...interface{}) (*MyRow, error)

type TableInfo

type TableInfo struct {
	Name   string      //表名
	Fields []FieldInfo //字段
}

type TableName

type TableName string

type XDBInf

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

type XDb

type XDb struct {
	*sql.DB
	// contains filtered or unexported fields
}

func OpenAdo

func OpenAdo(host, dbName, user, pwd string) (*XDb, error)

func OpenAdoSQL

func OpenAdoSQL(host, dbName, user, pwd string) (*XDb, error)

func OpenMssql

func OpenMssql(host, dbName, user, pwd string) (*XDb, error)

func OpenMssqlOdbc

func OpenMssqlOdbc(host, dbName, user, pwd string) (*XDb, error)

access "Driver={microsoft access driver(*.mdb)};dbq=*.mdb;uid=admin;pwd=pass;" dBase "Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=------------;" oracle "Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;" MSSQL server "Driver={sql server};server=servername;database=dbname;uid=sa;pwd=pass;" MS text "Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"

Visual Foxpro "Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;Exclusive=No;"

MySQL "Driver={mysql};database=yourdatabase;uid=username;pwd=yourpassword;option=16386;"

SQLite "Driver={SQLite3 ODBC Driver};Database=D:\SQLite\*.db"

PostgreSQL "Driver={PostgreSQL ANSI};server=127.0.0.1;uid=admin;pwd=pass;database=databaseName"

func OpenMyado

func OpenMyado(host, dbName, user, pwd string) (*XDb, error)

func OpenMysql

func OpenMysql(host, dbName, user, pwd, charset string) (*XDb, error)

func OpenNetsql

func OpenNetsql(host, dbName, user, pwd string) (*XDb, error)

db, err := dataset.OpenNetsql("58.221.46.81:1209", "dada", "129129")

func OpenODBC

func OpenODBC(connStr string) (*XDb, error)

func OpenODBCDSN

func OpenODBCDSN(user, pwd, dsn string) (*XDb, error)

func OpenOrcl

func OpenOrcl(host, dbName, user, pwd string) (*XDb, error)

func OpenOrclDror

func OpenOrclDror(host, dbName, user, pwd string) (*XDb, error)

`user="scott" password="tiger" connectString="dbhost:1521/orclpdb1"`

func OpenOrclGo

func OpenOrclGo(host, dbName, user, pwd string, inputConnStr string) (*XDb, error)

func OpenSqlLite3

func OpenSqlLite3(filename string) (*XDb, error)

func (*XDb) Begin

func (me *XDb) Begin() (*MyTx, error)

func (*XDb) DBQueryAll

func (me *XDb) DBQueryAll(sql string, args ...interface{}) ([]map[string]interface{}, error)

func (*XDb) DBQueryAllField

func (me *XDb) DBQueryAllField(sql string, args ...interface{}) ([]string, []map[string]interface{}, error)

func (*XDb) Delete

func (me *XDb) Delete(model interface{}) (int64, error)

根据主键删除一条数据,返回所影响的行

func (*XDb) Exec

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

func (*XDb) GetCallInfo

func (me *XDb) GetCallInfo() []byte

func (*XDb) GetDBName

func (me *XDb) GetDBName() string

func (*XDb) GetMysqlErrno

func (me *XDb) GetMysqlErrno(err error) int

func (*XDb) GetRowMap

func (me *XDb) GetRowMap() map[uint64]*MyRows

func (*XDb) Insert

func (me *XDb) Insert(model interface{}) error

将一个Struct结构体插入到数据库,如有自增自段, 会把自增值赋给model中的对应字段,model必须是可修改的,即传地址如,&m

func (*XDb) Load

func (me *XDb) Load(model interface{}) error

根据主键返回一条数据,并赋值到model中,model必须是可修改的,即传地址如,&m

func (*XDb) Lock

func (me *XDb) Lock()

func (*XDb) Prepare

func (me *XDb) Prepare(query string) (*MyStmt, error)

func (*XDb) Query

func (me *XDb) Query(query string, args ...interface{}) (*MyRows, error)

func (*XDb) QueryCount

func (me *XDb) QueryCount(query string, args ...interface{}) int

func (*XDb) QueryDataRows

func (me *XDb) QueryDataRows(query string, args ...interface{}) ([]DataRow, error)

func (*XDb) QueryRow

func (me *XDb) QueryRow(query string, args ...interface{}) (*MyRow, error)

func (*XDb) SetMaxOpenConns

func (me *XDb) SetMaxOpenConns(n int)

func (*XDb) Unlock

func (me *XDb) Unlock()

func (*XDb) Update

func (me *XDb) Update(model interface{}) (int64, error)

根据主键更新数据记录,返回所影响的行数

Jump to

Keyboard shortcuts

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