1
0
forked from sm/vain

Simplify some SQL

Change-Id: I0ea64662c90f948cd61bb1db855c139fa1be8a9e
This commit is contained in:
Stephen McQuay 2016-06-21 22:02:06 -07:00
parent 45c0af4d1e
commit 99cdbf1847
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D

11
db.go
View File

@ -137,10 +137,17 @@ func (db *DB) NSForToken(ns string, tok string) error {
}
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(
"INSERT INTO namespaces(ns, email) SELECT ?, users.email FROM users WHERE users.token = ?",
"INSERT INTO namespaces(ns, email) VALUES ($1, $2)",
ns,
tok,
email,
); err != nil {
return verrors.HTTP{
Message: fmt.Sprintf("problem inserting %q into namespaces for token %q: %v", ns, tok, err),