Book authors

This commit is contained in:
Meutel 2017-08-02 20:00:42 +02:00
parent b82967565b
commit 444c10cdc8

View File

@ -61,6 +61,7 @@ const (
BOOK QueryType = iota BOOK QueryType = iota
BOOK_TAGS QueryType = iota BOOK_TAGS QueryType = iota
BOOK_DATA QueryType = iota BOOK_DATA QueryType = iota
BOOK_AUTHORS QueryType = iota
BOOKS_COUNT QueryType = iota BOOKS_COUNT QueryType = iota
) )
@ -80,6 +81,7 @@ var QUERIES = map[Query]string{
Query{BOOK, false, false}: STMT_BOOK, Query{BOOK, false, false}: STMT_BOOK,
Query{BOOK_TAGS, false, false}: STMT_BOOK_TAGS, Query{BOOK_TAGS, false, false}: STMT_BOOK_TAGS,
Query{BOOK_DATA, false, false}: STMT_BOOK_DATA, Query{BOOK_DATA, false, false}: STMT_BOOK_DATA,
Query{BOOK_AUTHORS, false, false}: STMT_BOOK_AUTHORS,
Query{BOOKS_COUNT, false, false}: STMT_BOOKS_COUNT, Query{BOOKS_COUNT, false, false}: STMT_BOOKS_COUNT,
} }
var STMTS = make(map[Query]*sql.Stmt) var STMTS = make(map[Query]*sql.Stmt)
@ -320,6 +322,26 @@ func (app *Bouquins) queryBookData(book *BookFull) error {
return nil return nil
} }
func (app *Bouquins) queryBookAuthors(book *BookFull) error { func (app *Bouquins) queryBookAuthors(book *BookFull) error {
stmt, err := app.ps(BOOK_AUTHORS)
if err != nil {
return err
}
rows, err := stmt.Query(book.Id)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
author := new(Author)
var bookId int64
if err = rows.Scan(&author.Id, &author.Name, &bookId); err != nil {
return err
}
book.Authors = append(book.Authors, author)
}
if err := rows.Err(); err != nil {
return err
}
return nil return nil
} }