Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wux1an/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 the buffer into the database when the buffer is full.
https://github.com/wux1an/bufinsert
batch-insert buffer-insert bulk-insert database gorm sqlite
Last synced: about 15 hours ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/wux1an/bufinsert
- Owner: wux1an
- Created: 2021-11-25T17:00:19.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-25T17:09:11.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T21:05:29.589Z (5 months ago)
- Topics: batch-insert, buffer-insert, bulk-insert, database, gorm, sqlite
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bufinsert
An enhancement for [gorm](https://github.com/go-gorm/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
```bash
go get -u github.com/wux1an/bufinsert
```# Usage
```golang
package bufinsertimport (
"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
}
```