Rewrite XORM queries

This commit is contained in:
Thibault Meyer 2016-11-10 16:16:32 +01:00
parent c040f2fbb1
commit a4454f5d0f
No known key found for this signature in database
GPG key ID: BE39A108C4DDA755
22 changed files with 480 additions and 233 deletions

View file

@ -138,13 +138,20 @@ func GetLabelInRepoByID(repoID, labelID int64) (*Label, error) {
// it silently ignores label IDs that are not belong to the repository.
func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) {
labels := make([]*Label, 0, len(labelIDs))
return labels, x.Where("repo_id = ?", repoID).In("id", base.Int64sToStrings(labelIDs)).Asc("name").Find(&labels)
return labels, x.
Where("repo_id = ?", repoID).
In("id", base.Int64sToStrings(labelIDs)).
Asc("name").
Find(&labels)
}
// GetLabelsByRepoID returns all labels that belong to given repository by ID.
func GetLabelsByRepoID(repoID int64) ([]*Label, error) {
labels := make([]*Label, 0, 10)
return labels, x.Where("repo_id = ?", repoID).Asc("name").Find(&labels)
return labels, x.
Where("repo_id = ?", repoID).
Asc("name").
Find(&labels)
}
func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) {
@ -161,7 +168,11 @@ func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) {
}
labels := make([]*Label, 0, len(labelIDs))
return labels, e.Where("id > 0").In("id", base.Int64sToStrings(labelIDs)).Asc("name").Find(&labels)
return labels, e.
Where("id > 0").
In("id", base.Int64sToStrings(labelIDs)).
Asc("name").
Find(&labels)
}
// GetLabelsByIssueID returns all labels that belong to given issue by ID.
@ -197,7 +208,9 @@ func DeleteLabel(repoID, labelID int64) error {
if _, err = sess.Id(labelID).Delete(new(Label)); err != nil {
return err
} else if _, err = sess.Where("label_id = ?", labelID).Delete(new(IssueLabel)); err != nil {
} else if _, err = sess.
Where("label_id = ?", labelID).
Delete(new(IssueLabel)); err != nil {
return err
}
@ -293,7 +306,10 @@ func NewIssueLabels(issue *Issue, labels []*Label) (err error) {
func getIssueLabels(e Engine, issueID int64) ([]*IssueLabel, error) {
issueLabels := make([]*IssueLabel, 0, 10)
return issueLabels, e.Where("issue_id=?", issueID).Asc("label_id").Find(&issueLabels)
return issueLabels, e.
Where("issue_id=?", issueID).
Asc("label_id").
Find(&issueLabels)
}
// GetIssueLabels returns all issue-label relations of given issue by ID.