Documentation ¶
Index ¶
- Constants
- Variables
- func LogInit(t int)
- func Map(target interface{}, useTag string) (map[string]interface{}, error)
- func Scan(rows Rowss, target interface{}) error
- func ScanClose(rows Rowss, target interface{}) error
- func ScanMap(rows Rowss) ([]map[string]interface{}, error)
- func ScanMapClose(rows Rowss) ([]map[string]interface{}, error)
- func ScanMapDecode(rows Rowss) ([]map[string]interface{}, error)
- func ScanMapDecodeClose(rows Rowss) ([]map[string]interface{}, error)
- func SetTagName(name string)
- type ByteUnmarshaler
- type CloseErr
- type Config
- type DB
- func (db *DB) Begin() (tx *Tx, err error)
- func (db *DB) Exec(sql string, params ...interface{}) (ret sql.Result, err error)
- func (db *DB) Insert(obj interface{}) (err error)
- func (db *DB) Insert2(obj interface{}) (err error)
- func (db *DB) InsertOrUpdate(obj interface{}) (id string, err error)
- func (db *DB) InsertOrUpdate2(obj interface{}) (id string, err error)
- func (db *DB) Query(sql string, params ...interface{}) (rows *sql.Rows, err error)
- func (db *DB) Update(obj interface{}) (id string, err error)
- type Rows
- type Rowss
- type ScanErr
- type Tx
- func (tx *Tx) Commit() (err error)
- func (tx *Tx) Exec(sql string, params ...interface{}) (ret sql.Result, err error)
- func (tx *Tx) Insert(obj interface{}) (err error)
- func (tx *Tx) Insert2(obj interface{}) (err error)
- func (tx *Tx) InsertOrUpdate(obj interface{}) (id string, err error)
- func (tx *Tx) Query(sql string, params ...interface{}) (rows *sql.Rows, err error)
- func (tx *Tx) Rollback() (err error)
- func (tx *Tx) Update(obj interface{}) (id string, err error)
Constants ¶
const (
// DefaultTagName is the default struct tag name
DefaultTagName = "json"
)
Variables ¶
var ( Tag = "gorm" TableName = "TableName" )
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`) )
var ( // ErrNoneStructTarget as its name says ErrNoneStructTarget = errors.New("[scanner] target must be a struct type") )
Functions ¶
func Scan ¶
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 ¶
ScanClose is the same as Scan and helps you Close the rows Don't exec the rows.Close after calling this
func ScanMap ¶
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 ¶
ScanMapClose is the same as ScanMap and close the rows
func ScanMapDecode ¶
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 ¶
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.
Types ¶
type ByteUnmarshaler ¶
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()
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) InsertOrUpdate ¶
InsertOrUpdate InsertOrUpdate
func (*DB) InsertOrUpdate2 ¶
InsertOrUpdate2 InsertOrUpdate
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