mssql

package
v0.0.0-...-0c396f5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTagName is the default struct tag name
	DefaultTagName = "json"
)

Variables

View Source
var (
	Tag       = "gorm"
	TableName = "TableName"
)
View Source
var (

	//ErrTargetNotSettable means the second param of Bind is not settable
	ErrTargetNotSettable = errors.New("[scanner]: target is not settable! a pointer is required")
	//ErrNilRows means the first param can't be a nil
	ErrNilRows = errors.New("[scanner]: rows can't be nil")
	//ErrSliceToString means only []uint8 can be transmuted into string
	ErrSliceToString = errors.New("[scanner]: can't transmute a non-uint8 slice to string")
	//ErrEmptyResult occurs when target of Scan isn't slice and the result of the query is empty
	ErrEmptyResult = errors.New(`[scanner]: empty result`)
)
View Source
var (
	// ErrNoneStructTarget as its name says
	ErrNoneStructTarget = errors.New("[scanner] target must be a struct type")
)

Functions

func LogInit

func LogInit(t int)

func Map

func Map(target interface{}, useTag string) (map[string]interface{}, error)

Map converts a struct to a map type for each field of the struct must be built-in type

func Scan

func Scan(rows Rowss, target interface{}) error

Scan scans data from rows to target Don't forget to close the rows When the target is not a pointer of slice, ErrEmptyResult may be returned if the query result is empty

func ScanClose

func ScanClose(rows Rowss, target interface{}) error

ScanClose is the same as Scan and helps you Close the rows Don't exec the rows.Close after calling this

func ScanMap

func ScanMap(rows Rowss) ([]map[string]interface{}, error)

ScanMap returns the result in the form of []map[string]interface{} json.Marshal encodes []byte as a base64 string, while in most cases it's expected to be encoded as string or int. If you want this, use ScanMapDecode instead.

func ScanMapClose

func ScanMapClose(rows Rowss) ([]map[string]interface{}, error)

ScanMapClose is the same as ScanMap and close the rows

func ScanMapDecode

func ScanMapDecode(rows Rowss) ([]map[string]interface{}, error)

ScanMapDecode returns the result in the form of []map[string]interface{} If possible, it will convert []uint8 to int or float64, or it will convert []uint8 to string

func ScanMapDecodeClose

func ScanMapDecodeClose(rows Rowss) ([]map[string]interface{}, error)

ScanMapDecodeClose returns the result in the form of []map[string]interface{} If possible, it will convert []uint8 to int or float64, or it will convert []uint8 to string. It will close the rows in the end.

func SetTagName

func SetTagName(name string)

SetTagName can be set only once

Types

type ByteUnmarshaler

type ByteUnmarshaler interface {
	UnmarshalByte(data []byte) error
}

ByteUnmarshaler is the interface implemented by types that can unmarshal a JSON description of themselves. The input can be assumed to be a valid encoding of a JSON value. UnmarshalByte must copy the JSON data if it wishes to retain the data after returning.

By convention, to approximate the behavior of Unmarshal itself, ByteUnmarshaler implement UnmarshalByte([]byte("null")) as a no-op.

type CloseErr

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

CloseErr is the error occurs when rows.Close()

func (CloseErr) Error

func (e CloseErr) Error() string

type Config

type Config struct {
	DSN     string   // write data source name.
	ReadDSN []string // read data source name.
	Active  int      // pool
	Idle    int      // pool
}

type DB

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

func New

func New(conf Config) (db *DB, err error)

func (*DB) Begin

func (db *DB) Begin() (tx *Tx, err error)

Query extend sql.DB

func (*DB) Exec

func (db *DB) Exec(sql string, params ...interface{}) (ret sql.Result, err error)

Exec sql 更新或者插入使用

func (*DB) Insert

func (db *DB) Insert(obj interface{}) (err error)

func (*DB) Insert2

func (db *DB) Insert2(obj interface{}) (err error)

func (*DB) InsertOrUpdate

func (db *DB) InsertOrUpdate(obj interface{}) (id string, err error)

InsertOrUpdate InsertOrUpdate

func (*DB) InsertOrUpdate2

func (db *DB) InsertOrUpdate2(obj interface{}) (id string, err error)

InsertOrUpdate2 InsertOrUpdate

func (*DB) Query

func (db *DB) Query(sql string, params ...interface{}) (rows *sql.Rows, err error)

Query extend sql.DB

func (*DB) Update

func (db *DB) Update(obj interface{}) (id string, err error)

Update

type Rows

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

type Rowss

type Rowss interface {
	Close() error

	Columns() ([]string, error)

	ColumnTypes() ([]*sql.ColumnType, error)

	Next() bool

	Scan(dest ...interface{}) error
}

Rows defines methods that scanner needs, which database/sql.Rows already implements

type ScanErr

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

ScanErr will be returned if an underlying type couldn't be AssignableTo type of target field

func (ScanErr) Error

func (s ScanErr) Error() string

type Tx

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

Tx transaction.

func (*Tx) Commit

func (tx *Tx) Commit() (err error)

func (*Tx) Exec

func (tx *Tx) Exec(sql string, params ...interface{}) (ret sql.Result, err error)

Exec sql 更新或者插入使用

func (*Tx) Insert

func (tx *Tx) Insert(obj interface{}) (err error)

Insert insert

func (*Tx) Insert2

func (tx *Tx) Insert2(obj interface{}) (err error)

Insert2 insert

func (*Tx) InsertOrUpdate

func (tx *Tx) InsertOrUpdate(obj interface{}) (id string, err error)

InsertOrUpdate InsertOrUpdate

func (*Tx) Query

func (tx *Tx) Query(sql string, params ...interface{}) (rows *sql.Rows, err error)

Query extend sql.DB

func (*Tx) Rollback

func (tx *Tx) Rollback() (err error)

func (*Tx) Update

func (tx *Tx) Update(obj interface{}) (id string, err error)

Insert insert

Jump to

Keyboard shortcuts

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