Simplify some SQL
Change-Id: I0ea64662c90f948cd61bb1db855c139fa1be8a9e
This commit is contained in:
parent
45c0af4d1e
commit
99cdbf1847
11
db.go
11
db.go
@ -137,10 +137,17 @@ func (db *DB) NSForToken(ns string, tok string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
|
var email string
|
||||||
|
if err = txn.Get(&email, "SELECT email FROM users WHERE token = $1", tok); err != nil {
|
||||||
|
return verrors.HTTP{
|
||||||
|
Message: fmt.Sprintf("could not find user for token %q", tok),
|
||||||
|
Code: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
if _, err = txn.Exec(
|
if _, err = txn.Exec(
|
||||||
"INSERT INTO namespaces(ns, email) SELECT ?, users.email FROM users WHERE users.token = ?",
|
"INSERT INTO namespaces(ns, email) VALUES ($1, $2)",
|
||||||
ns,
|
ns,
|
||||||
tok,
|
email,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return verrors.HTTP{
|
return verrors.HTTP{
|
||||||
Message: fmt.Sprintf("problem inserting %q into namespaces for token %q: %v", ns, tok, err),
|
Message: fmt.Sprintf("problem inserting %q into namespaces for token %q: %v", ns, tok, err),
|
||||||
|
Loading…
Reference in New Issue
Block a user