Update to pg v9

This commit is contained in:
Las Zenow 2019-11-06 06:53:41 +00:00
parent 91beca9a55
commit defaa2ae0b
9 changed files with 75 additions and 44 deletions

View file

@ -4,26 +4,26 @@ import (
"strings"
"time"
"github.com/go-pg/pg"
"github.com/go-pg/pg/v9"
)
// Book metadata
type Book struct {
ID string `sql:"type:varchar(16)"`
ID string `pg:"type:varchar(16)"`
Title string
Authors []string `sql:"authors" pg:",array"`
Authors []string `pg:"authors,array"`
Contributor string
Publisher string
Description string
Tags []string `sql:"tags" pg:",array"`
Tags []string `pg:"tags,array"`
Date string
Lang string `sql:"type:varchar(3)"`
Isbn string `sql:"type:varchar(13)"`
FileSize int `sql:"type:integer"`
Cover bool `sql:",notnull"`
Active bool `sql:",notnull"`
UploadDate time.Time `sql:"type:timestamp"`
Tsv string `sql:"type:tsvector"`
Lang string `pg:"type:varchar(3)"`
Isbn string `pg:"type:varchar(13)"`
FileSize int `pg:"type:integer"`
Cover bool `pg:",notnull"`
Active bool `pg:",notnull"`
UploadDate time.Time `pg:"type:timestamp"`
Tsv string `pg:"type:tsvector"`
Visit *Visit
}
@ -156,7 +156,7 @@ func (db *pgDB) ActiveBook(id string) error {
func (db *pgDB) IsBookActive(id string) bool {
var active []bool
err := db.sql.Model(&Book{}).
Column("active").
Relation("active").
Where("id = ?", id).
Select(&active)
if err != nil || len(active) != 1 {