Coder Social home page Coder Social logo

sqlext's Introduction

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
}

sqlext's People

Contributors

btfak avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.