ch9.5
This commit is contained in:
@@ -138,12 +138,14 @@ func (m MovieModel) GetAll(title string, genres []string, filter Filters) ([]*Mo
|
||||
query := `
|
||||
SELECT id, created_at, title, year, runtime, genres, version
|
||||
FROM movies
|
||||
WHERE (to_tsvector('simple', title) @@ plainto_tsquery('simple', $1) OR $1 = '')
|
||||
AND (genres @> $2 OR $2 = '{}')
|
||||
ORDER BY id`
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
rows, err := m.DB.QueryContext(ctx, query)
|
||||
rows, err := m.DB.QueryContext(ctx, query, title, pq.Array(genres))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user