Update Paste to allow for clumps
parent
9cec9fd3e1
commit
7ce90c3673
|
@ -7,6 +7,7 @@ type Paste struct {
|
|||
ID int
|
||||
Filename string
|
||||
Handle uuid.UUID
|
||||
ClumpID int
|
||||
}
|
||||
|
||||
//PasteRepository puts/gets a paste from the database
|
||||
|
@ -24,7 +25,7 @@ func (db *DatabaseConnector) GetPaste(handle uuid.UUID) (Paste, error) {
|
|||
row := db.DB.QueryRow("SELECT * FROM paste WHERE handle=$1", handle)
|
||||
paste := Paste{}
|
||||
|
||||
return paste, row.Scan(&paste.ID, &paste.Filename, &paste.Handle)
|
||||
return paste, row.Scan(&paste.ID, &paste.Filename, &paste.Handle, &paste.ClumpID)
|
||||
}
|
||||
|
||||
// PutPaste puts a paste in the database
|
||||
|
@ -34,7 +35,8 @@ func (db *DatabaseConnector) PutPaste(filename string) (Paste, error) {
|
|||
return Paste{}, err
|
||||
}
|
||||
|
||||
insertResult := db.DB.QueryRow("INSERT INTO paste VALUES(DEFAULT, $1, $2) RETURNING pasteID", filename, handle.String())
|
||||
// TODO: add ability to insert a clump
|
||||
insertResult := db.DB.QueryRow("INSERT INTO paste VALUES(DEFAULT, $1, $2, NULL) RETURNING pasteID", filename, handle.String())
|
||||
|
||||
var pasteID int
|
||||
err = insertResult.Scan(&pasteID)
|
||||
|
@ -51,9 +53,9 @@ func (db *DatabaseConnector) PutPaste(filename string) (Paste, error) {
|
|||
}
|
||||
|
||||
// UpdatePaste allows for a paste to be updated.
|
||||
// Currently, only the filename can be updated
|
||||
// Currently, only the filename and clump id can be updated
|
||||
func (db *DatabaseConnector) UpdatePaste(paste Paste) error {
|
||||
_, err := db.DB.Exec("UPDATE paste SET filename = $1 WHERE pasteID = $2", paste.Filename, paste.ID)
|
||||
_, err := db.DB.Exec("UPDATE paste SET filename = $1, clumpID = $2 WHERE pasteID = $3", paste.Filename, paste.ClumpID, paste.ID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue