// Copyright 2019 Drone IO, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package user import ( "database/sql" "github.com/drone/drone/core" "github.com/drone/drone/store/shared/db" ) // helper function converts the User structure to a set // of named query parameters. func toParams(u *core.User) map[string]interface{} { return map[string]interface{}{ "user_id": u.ID, "user_login": u.Login, "user_email": u.Email, "user_admin": u.Admin, "user_machine": u.Machine, "user_active": u.Active, "user_avatar": u.Avatar, "user_syncing": u.Syncing, "user_synced": u.Synced, "user_created": u.Created, "user_updated": u.Updated, "user_last_login": u.LastLogin, "user_oauth_token": u.Token, "user_oauth_refresh": u.Refresh, "user_oauth_expiry": u.Expiry, "user_hash": u.Hash, } } // helper function scans the sql.Row and copies the column // values to the destination object. func scanRow(scanner db.Scanner, dest *core.User) error { return scanner.Scan( &dest.ID, &dest.Login, &dest.Email, &dest.Admin, &dest.Machine, &dest.Active, &dest.Avatar, &dest.Syncing, &dest.Synced, &dest.Created, &dest.Updated, &dest.LastLogin, &dest.Token, &dest.Refresh, &dest.Expiry, &dest.Hash, ) } // helper function scans the sql.Row and copies the column // values to the destination object. func scanRows(rows *sql.Rows) ([]*core.User, error) { defer rows.Close() users := []*core.User{} for rows.Next() { user := new(core.User) err := scanRow(rows, user) if err != nil { return nil, err } users = append(users, user) } return users, nil }