Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CreateMany #6

Merged
merged 3 commits into from
Dec 13, 2019
Merged

feat: CreateMany #6

merged 3 commits into from
Dec 13, 2019

Conversation

sljeff
Copy link
Owner

@sljeff sljeff commented Dec 12, 2019

Make sure these boxes checked before submitting your pull request.

  • Do only one thing
  • No API-breaking changes
  • New code/logic commented & tested

For significant changes like big bug fixes, new features, please open an issue to make an agreement on an implementation design/plan first before starting it.

What did this pull request do?

CreateMany

// mysql and sqlite: insert multiple; insert multiple ignore duplicate
// postgresql and mssql do not support ignore
db.CreateMany([]interface{}{&user1, &user2, &user3}, gorm.IGNORE)
db.CreateMany([]interface{}{&user1, &user2, &user3})

// mysql: insert on conflict update
db.CreateMany([]interface{}{&user1, &user2, &user3}, &User{UpdatedAt: now})

// postgresql: insert on confilct update
db.CreateMany([]interface{}{&user1, &user2, &user3}, 'constraint_name', &User{UpdatedAt: now})

// Caution: mssql db driver will not raise error on duplicate
db.CreateMany([]interface{}{&user1, &user1, &user1})

@codecov
Copy link

codecov bot commented Dec 12, 2019

Codecov Report

Merging #6 into master will increase coverage by 0.08%.
The diff coverage is 95.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   85.97%   86.06%   +0.08%     
==========================================
  Files          24       24              
  Lines        3601     3645      +44     
==========================================
+ Hits         3096     3137      +41     
- Misses        398      400       +2     
- Partials      107      108       +1
Impacted Files Coverage Δ
scope.go 89.44% <100%> (+0.15%) ⬆️
main.go 83.4% <80%> (-0.41%) ⬇️
callback_create.go 92.77% <97.82%> (+0.91%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3cbd9d7...b07f8d4. Read the comment docs.

@sljeff sljeff merged commit 73d6d87 into master Dec 13, 2019
@sljeff
Copy link
Owner Author

sljeff commented Dec 13, 2019

@sljeff sljeff deleted the feat-create-many branch December 13, 2019 05:11
@Arcayr
Copy link

Arcayr commented Jan 25, 2020

Could you make a PR for this on @jinzhu's gorm repo?

Much appreciated.

@sljeff
Copy link
Owner Author

sljeff commented Feb 16, 2020

Could you make a PR for this on @jinzhu's gorm repo?

Much appreciated.

GORM v2 is on going: https://github.com/jinzhu/gorm/issues/2886#issue-565836194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants