diff --git a/database/pkg.go b/database/pkg.go index 50695a5..6cab492 100644 --- a/database/pkg.go +++ b/database/pkg.go @@ -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 }// }}} diff --git a/pkg.go b/pkg.go index a8efe5a..3ea745c 100644 --- a/pkg.go +++ b/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)