GORM: Batch Operations

Sumit Agarwal
Aug 22, 2020
Image Source: Google

GORM is the ORM library for Golang, built and maintained by Jinzhu. Since you have stumbled upon this article I would safely assume that you have been coding using GoLang for a while now and are a GORM user already.

I have been working with gorm for a while now and recently had a use case where I wanted to perform bulk writes to MySQL database. Upon exploring the documentation, I found that gorm doesn’t support bulk writes/updates (in V1). I went through the open items on their GitHub repo and found some helpful comments which led me to write this small function, which supports batch upserts for GORM.

Update: GORM V2 provides bulk operations out of the box.

Please find all of my gorm-plugin listed here.

--

--

Sumit Agarwal

I am a software developer at heart who likes to travel and has a profound interest in design, art, and literature.