-
Notifications
You must be signed in to change notification settings - Fork 30
refactor(database): move repo logic into separate package #687
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
Conversation
…to refactor/database/repo
Codecov Report
@@ Coverage Diff @@
## main #687 +/- ##
==========================================
- Coverage 55.09% 55.09% -0.01%
==========================================
Files 201 210 +9
Lines 15959 15912 -47
==========================================
- Hits 8793 8767 -26
+ Misses 6788 6768 -20
+ Partials 378 377 -1
|
wass3r
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see you replaced .Scan() with .Take() in a few places. based on GORM docs (https://gorm.io/docs/query.html#Retrieving-a-single-object), it looks like Take already does LIMIT 1? Can we remove the preceding .Limit(1) in those instances? clearly it passed unit testing so it must account for it somehow?
|
@wass3r good catch! 👍 To provide some context in case anyone is curious, this is the reason why we're using https://gorm.io/docs/v2_release_note.html#ErrRecordNotFound In short, for several of our DB queries, we expect an error if the record doesn't exist. However, In order to account for this today, we have extra code across our DB package that does this: server/database/postgres/repo.go Lines 37 to 40 in 2f14f38
Links for reference: |
ecrupper
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Based off of #574 and #663
This change continues the refactor efforts initially introduced in the above PRs.
This adds a new
repopackage to thegithub.amrom.workers.dev/go-vela/server/databasepackage.This contains a
RepoServiceinterface declaring all functions necessary for repo based interactions with the database:server/database/repo/service.go
Lines 11 to 51 in b296e48
This package also contains the
enginewhich implements the above service interface:server/database/repo/repo.go
Lines 25 to 39 in b296e48
This
enginecontains no raw SQL queries for integrating with therepostable.Instead, we leverage our DB library's (https://gorm.io/) agnostic abstraction for integrating with that table.