1
0
Fork 0

DB query queueing

This commit is contained in:
Gregory Eremin 2015-03-21 21:10:50 +07:00
parent eff7d6e39b
commit 0c7c07adb4
1 changed files with 14 additions and 1 deletions

View File

@ -10,12 +10,14 @@ import (
)
var (
db *sqlx.DB
db *sqlx.DB
queryQueue = make(chan func(), 1000)
)
func Connect(params string) (err error) {
db, err = sqlx.Connect("mysql", params)
db.Mapper = reflectx.NewMapper("json")
go processQueue()
return
}
@ -42,6 +44,17 @@ func mustSelectN(dest interface{}, query string, params interface{}) {
}
}
func Queue(fun func()) {
queryQueue <- fun
}
func processQueue() {
for {
fun := <-queryQueue
fun()
}
}
func measure(op string, start time.Time) {
duration := time.Since(start).Nanoseconds()
outcome := "succeeded"