harness-drone/store/perm/scan.go

77 lines
1.7 KiB
Go
Raw Normal View History

2019-02-19 23:56:41 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
package perm
import (
"database/sql"
"github.com/drone/drone/store/shared/db"
"github.com/drone/drone/core"
)
// helper function converts the Perm structure to a set
// of named query parameters.
func toParams(perm *core.Perm) map[string]interface{} {
return map[string]interface{}{
"perm_user_id": perm.UserID,
"perm_repo_uid": perm.RepoUID,
"perm_read": perm.Read,
"perm_write": perm.Write,
"perm_admin": perm.Admin,
"perm_synced": perm.Synced,
"perm_created": perm.Created,
"perm_updated": perm.Updated,
}
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanRow(scanner db.Scanner, dst *core.Perm) error {
return scanner.Scan(
&dst.UserID,
&dst.RepoUID,
&dst.Read,
&dst.Write,
&dst.Admin,
&dst.Synced,
&dst.Created,
&dst.Updated,
)
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanCollabRow(scanner db.Scanner, dst *core.Collaborator) error {
return scanner.Scan(
&dst.UserID,
&dst.RepoUID,
&dst.Login,
&dst.Avatar,
&dst.Read,
&dst.Write,
&dst.Admin,
&dst.Synced,
&dst.Created,
&dst.Updated,
)
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanCollabRows(rows *sql.Rows) ([]*core.Collaborator, error) {
defer rows.Close()
collabs := []*core.Collaborator{}
for rows.Next() {
collab := new(core.Collaborator)
err := scanCollabRow(rows, collab)
if err != nil {
return nil, err
}
collabs = append(collabs, collab)
}
return collabs, nil
}