extend gorm and gocql
Switch branches/tags
Nothing to show
Clone or download
yanglong.2017 refactor: readme
Change-Id: I53ea4a6c4ec8d08d974002f3a72de00e862da869
Latest commit dd79c5b Nov 1, 2017
Failed to load latest commit information.
.gitignore Initial commit Nov 1, 2017
LICENSE Initial commit Nov 1, 2017
README.md refactor: readme Nov 1, 2017
sql.go feat: extend gorm and gocql Nov 1, 2017
sql_test.go feat: extend gorm and gocql Nov 1, 2017



sqlext use to extend gorm and gocql

  • gorm not support batch insert,BatchInsert is a universal batch insert API.
  • gocql not support bind querying data to struct,MapToStruct fill struct fields with map value


  • BatchInsert
type GroupMember struct {
	ID        int64
	GroupID   int64
	Type      int8
	Extra     []byte
	JoinTime  time.Time

var mydb *gorm.DB
var members = []GroupMember{}

//generated SQL: INSERT INTO group_member (id, group_id, type, extra, join_time) VALUES (?,?,?,?,?), (?,?,?,?,?) ...
  • MapToStruct
// MapToStruct
func GetUsersByIDs(userIDs []int64) (users []User, err error) {
	iter := Cassandra.Query("SELECT * FROM user WHERE id IN ?", userIDs).Iter()
	for {
		row := make(map[string]interface{})
		if !iter.MapScan(row) {
		user := User{}
		err = sqlext.MapToStruct(row, &user)
		if err != nil {
			return nil, err
		users = append(users, user)
	return users, nil