Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Created March 26, 2021 11:47
Show Gist options
  • Save yutakahashi114/8b7972032b67045ad44aec0754923e42 to your computer and use it in GitHub Desktop.
Save yutakahashi114/8b7972032b67045ad44aec0754923e42 to your computer and use it in GitHub Desktop.
func splitInsert(db xorm.Interface, us users) error {
const limit = 100
for start := 0; start < us.Len(); start += limit {
end := start + limit
if end > us.Len() {
end = us.Len()
}
target := us[start:end]
_, err := db.Insert(&target)
if err != nil {
return err
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment