Add get count all items from db, and review result struct

This commit is contained in:
Shuhrat Tultaganov committed 2023-01-26 22:07:44 +03:00
1 parent 88ae5fa188
commit f6bca0590f
3 files changed
+42 -4

No files matched your search

+13
View File
@@ -51,6 +51,19 @@ func (f *Filmsrepo) FindByAll() (*[]model.Films, error) {
return &buffs, nil
}
func (f *Filmsrepo) GetCountFilms() (*int, error) {
rows, err := f.db.db.Query(context.Background(), "SELECT count(*) FROM films")
var count int
if err != nil {
return nil, err
}
for rows.Next() {
rows.Scan(&count)
}
return &count, nil
}
func (f *Filmsrepo) FindById(id string) (*model.Films, error) {
query := fmt.Sprintf("SELECT * FROM films WHERE Id = %s;", id)
var buff model.Films