Update to use pg/v10

This commit is contained in:
Las Zenow 2020-11-30 19:03:31 +00:00
parent 94c75b1d2a
commit 1536d97d8d
13 changed files with 449 additions and 98 deletions

View file

@ -1,7 +1,7 @@
package database
import (
"github.com/go-pg/pg/v9"
"github.com/go-pg/pg/v10"
)
type BookLister interface {
@ -20,16 +20,16 @@ type BookList struct {
Title string
Description []string `pg:"description,array"`
UserID int `pg:"type:integer"`
User *User
Books []Book `pg:"many2many:book_list_entries"`
User *User `pg:"rel:has-one"`
Books []Book `pg:"many2many:book_list_entries"`
}
type BookListEntry struct {
ID int `pg:"type:serial"`
BookListID int `pg:"type:integer"`
BookList *BookList
BookID string `pg:"type:varchar(16)"`
Book *Book
ID int `pg:"type:serial"`
BookListID int `pg:"type:integer"`
BookList *BookList `pg:"rel:has-one"`
BookID string `pg:"type:varchar(16)"`
Book *Book `pg:"rel:has-one"`
}
func (db *pgDB) NewBookList(listID, title, username string, description []string) error {
@ -37,12 +37,14 @@ func (db *pgDB) NewBookList(listID, title, username string, description []string
if err != nil {
return err
}
return db.sql.Insert(&BookList{
_, err = db.sql.Model(&BookList{
ListID: listID,
Title: title,
Description: description,
UserID: user.ID,
})
}).Insert()
return err
}
func (db *pgDB) AddBookToList(listID, bookID string) error {
@ -51,10 +53,11 @@ func (db *pgDB) AddBookToList(listID, bookID string) error {
return err
}
return db.sql.Insert(&BookListEntry{
_, err = db.sql.Model(&BookListEntry{
BookListID: list.ID,
BookID: bookID,
})
}).Insert()
return err
}
func (db *pgDB) DeleteBookFromList(listID, bookID string) error {