Add postgres package
This commit is contained in:
parent
f759600db1
commit
c0d6ae1157
22
postsgres/userservice.go
Normal file
22
postsgres/userservice.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package postgres
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserService represents a PostgreSQL implementation of myapp.UserService.
|
||||||
|
type UserService struct {
|
||||||
|
DB *sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
// User returns a user for a given id.
|
||||||
|
func (s *UserService) User(id int) (*budgeteer.User, error) {
|
||||||
|
var u budgeteer.User
|
||||||
|
row := s.DB.QueryRow(`SELECT id, email, password FROM users WHERE id = $1`, id)
|
||||||
|
if err := row.Scan(&u.ID, &u.Email, &u.Password); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &u, nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user