Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 570 Bytes

APIDESIGN.md

File metadata and controls

30 lines (26 loc) · 570 Bytes

API Design

Model interface

type IModel interface {
	TableName() string
	PK() string
}

Remove the V1 version DbName(),Use the Use() function instead

Use sqlx

gosql.Sqlx() //return native sqlx

Change database

gosql.Use(name string) 
gosql.Use(db).Table("xxxx").Where("id = ?",1).Update(map[string]interface{}{"name":"test"})
gosql.Use(db).Model(&Users{}}).Get()

Transaction context switching

gosql.Use(db).Tx(func(tx *gosql.DB){
    tx.Table("xxxx").Where("id = ?",1).Get(&user)
    tx.Model(&Users{}).Get()	
})