Fix bug where pq does not support LastInsertID
parent
c72589bb7b
commit
24923ae1e4
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue