Answer the question
In order to leave comments, you need to log in
How to bulk insert in GORM?
Greetings!
There is an array of structures that need to be written to the appropriate database table using GORM.
Now I do it with a loop and gorm DB.Create one at a time.
How to save them all at once? DB.Create does not accept an array.
Answer the question
In order to leave comments, you need to log in
You can use the library https://github.com/t-tiger/gorm-bulk-insert
If you don't want to pull unnecessary dependencies into the project, you can wrap the cycle in a transaction, this will give a performance gain close to normal bulk insert.
Approximately like this:
tx.Begin()
for {
DB.Create
}
tx.Commit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question