add bulk genre insert

This commit is contained in:
sentriz
2020-12-30 14:59:33 +00:00
parent 8c0473e7f6
commit 3e8884450f
2 changed files with 48 additions and 36 deletions

View File

@@ -5,6 +5,7 @@ import (
"log"
"net/url"
"os"
"strings"
"github.com/gorilla/securecookie"
"github.com/jinzhu/gorm"
@@ -112,6 +113,21 @@ func (db *DB) GetOrCreateKey(key string) string {
return value
}
func (db *DB) InsertBulkLeftMany(table string, head []string, left int, col []int) error {
var rows []string
var values []interface{}
for _, c := range col {
rows = append(rows, "(?, ?)")
values = append(values, left, c)
}
q := fmt.Sprintf("INSERT OR IGNORE INTO %q (%s) VALUES %s",
table,
strings.Join(head, ", "),
strings.Join(rows, ", "),
)
return db.Exec(q, values...).Error
}
func (db *DB) GetUserByID(id int) *User {
user := &User{}
err := db.
@@ -136,6 +152,10 @@ func (db *DB) GetUserByName(name string) *User {
return user
}
func (db *DB) Begin() *DB {
return &DB{DB: db.DB.Begin()}
}
type ChunkFunc func(*gorm.DB, []int64) error
func (db *DB) TransactionChunked(data []int64, cb ChunkFunc) error {