Fix bug where pq does not support LastInsertID

master
Nick Krichevsky 2019-03-10 00:07:33 -05:00
parent c72589bb7b
commit 24923ae1e4
1 changed files with 4 additions and 3 deletions

View File

@ -34,13 +34,14 @@ func (db *DatabaseConnector) PutPaste(title string) (Paste, error) {
return Paste{}, err
}
insertResult, err := db.DB.Exec("INSERT INTO paste VALUES(DEFAULT, $1, $2)", title, handle.String())
insertResult := db.DB.QueryRow("INSERT INTO paste VALUES(DEFAULT, $1, $2) RETURNING pasteID", title, handle.String())
var pasteID int
err = insertResult.Scan(&pasteID)
if err != nil {
return Paste{}, err
}
pasteID, err := insertResult.LastInsertId()
return Paste{
// Even though pasteID is an int64, Postgres' SERIAL is 32 bits, and int is defined to be >= 32 bits
ID: int(pasteID),