Return ID when creating a user
This commit is contained in:
parent
15abdd4081
commit
c848ae60b5
@ -236,8 +236,9 @@ func (db *T) UpdateUserTime(userID int) (err error) {// {{{
|
||||
return
|
||||
}// }}}
|
||||
|
||||
func (db *T) CreateUser(username, password, name string) (err error) {// {{{
|
||||
_, err = db.Conn.Exec(`
|
||||
func (db *T) CreateUser(username, password, name string) (userID int64, err error) {// {{{
|
||||
var row *sql.Row
|
||||
row = db.Conn.QueryRow(`
|
||||
INSERT INTO _webservice.user(username, password, name)
|
||||
VALUES(
|
||||
$1,
|
||||
@ -250,11 +251,14 @@ func (db *T) CreateUser(username, password, name string) (err error) {// {{{
|
||||
),
|
||||
$3
|
||||
)
|
||||
RETURNING id
|
||||
`,
|
||||
username,
|
||||
password,
|
||||
name,
|
||||
)
|
||||
|
||||
err = row.Scan(&userID)
|
||||
return
|
||||
}// }}}
|
||||
|
||||
|
6
pkg.go
6
pkg.go
@ -223,7 +223,7 @@ func (service *Service) InitDatabaseConnection() (err error) { // {{{
|
||||
}
|
||||
return
|
||||
} // }}}
|
||||
func (service *Service) CreateUser(username, password, name string) (err error) { // {{{
|
||||
func (service *Service) CreateUser(username, password, name string) (userID int64, err error) { // {{{
|
||||
if service.Db != nil {
|
||||
err = service.InitDatabaseConnection()
|
||||
if err != nil {
|
||||
@ -231,7 +231,7 @@ func (service *Service) CreateUser(username, password, name string) (err error)
|
||||
}
|
||||
}
|
||||
|
||||
err = service.Db.CreateUser(username, password, name)
|
||||
userID, err = service.Db.CreateUser(username, password, name)
|
||||
return
|
||||
} // }}}
|
||||
func (service *Service) CreateUserPrompt() { // {{{
|
||||
@ -251,7 +251,7 @@ func (service *Service) CreateUserPrompt() { // {{{
|
||||
password, _ = reader.ReadString('\n')
|
||||
password = strings.TrimSpace(password)
|
||||
|
||||
err = service.CreateUser(username, password, name)
|
||||
_, err = service.CreateUser(username, password, name)
|
||||
if err != nil {
|
||||
service.logger.Error("application", "error", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user