Skip to content

An enhancement for gorm bulk insert. This can help you save the data to the buffer first, and then insert the all data in the buffer into the database when the buffer is full.

Notifications You must be signed in to change notification settings

wux1an/bufinsert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bufinsert

An enhancement for gorm bulk insert. This can help you save the data to the buffer first, and then insert the all data in buffer into database when the buffer is full.

Install

go get -u github.com/wux1an/bufinsert

Usage

package bufinsert

import (
	"gorm.io/gorm"
)

func ExampleNewInserter() {
	var db = &gorm.DB{} // fake database
	var inserter = NewInserter(db, 2)

	for i := 0; i < 11; i++ {
		go inserter.Insert(i)
	}

	inserter.Flush() // flush and empty
}

func ExampleBufferedInserter_Insert() {
	var db = &gorm.DB{} // fake database
	var inserter = NewInserter(db, 2)

	// way 1
	inserter.Insert("1") // not flush
	inserter.Insert("2") // flush and empty
	inserter.Insert("3") // not flush
	// way 2
	inserter.Insert([]interface{}{"4", "5", "6", "7"})

	inserter.Flush() // flush and empty
}

About

An enhancement for gorm bulk insert. This can help you save the data to the buffer first, and then insert the all data in the buffer into the database when the buffer is full.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages