summary refs log tree commit diff stats
path: root/account/getid.go
blob: 4f6da696a49a240df903ae020d135a47adff7f73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package account

import (
	"log"

	"tildegit.org/andinus/perseus/storage"
)

// GetID returns id from username.
func (u *User) GetID(db *storage.DB) error {
	// Acquire read lock on database.
	db.Mu.RLock()
	defer db.Mu.RUnlock()

	// Get password for this user from the database.
	stmt, err := db.Conn.Prepare("SELECT id FROM accounts WHERE username = ?")
	if err != nil {
		log.Printf("account/getid.go: %s\n",
			"failed to prepare statement")
		return err
	}
	defer stmt.Close()

	var id string
	err = stmt.QueryRow(u.Username).Scan(&id)
	if err != nil {
		log.Printf("account/getid.go: %s\n",
			"query failed")
	}
	u.ID = id

	return err
}