Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

README.md

sqlext

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

example

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

var mydb *gorm.DB
var members = []GroupMember{}
sqlext.BatchInsert(mydb.DB(),members)

//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) {
			break
		}
		user := User{}
		err = sqlext.MapToStruct(row, &user)
		if err != nil {
			return nil, err
		}
		users = append(users, user)
	}
	return users, nil
}

About

extend gorm and gocql

Topics

Resources

License

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.