1
0

Put Categories() down under the New*, Edit*, and DeleteCategory methods.

This commit is contained in:
Alexander Andreev 2023-05-23 04:31:22 +04:00
parent ca51617f0e
commit d18374e72a
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -201,34 +201,6 @@ func (s *SQLiteMindflow) Posts() (posts []mindflow.Post, err error) {
return posts, nil return posts, nil
} }
func (s *SQLiteMindflow) Categories() (categories []mindflow.Category, err error) {
tx, err := s.db.Begin()
if err != nil {
return nil, err
}
defer tx.Rollback()
rows, err := tx.Stmt(stmtCategoryGetAll).Query()
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var category mindflow.Category
if err = rows.Scan(&category.ID, &category.Name); err != nil {
return nil, err
}
categories = append(categories, category)
}
tx.Commit()
return categories, nil
}
func (s *SQLiteMindflow) NewCategory(category *mindflow.Category) (int64, error) { func (s *SQLiteMindflow) NewCategory(category *mindflow.Category) (int64, error) {
tx, err := s.db.Begin() tx, err := s.db.Begin()
if err != nil { if err != nil {
@ -284,6 +256,34 @@ func (s *SQLiteMindflow) DeleteCategory(id int64) (err error) {
return nil return nil
} }
func (s *SQLiteMindflow) Categories() (categories []mindflow.Category, err error) {
tx, err := s.db.Begin()
if err != nil {
return nil, err
}
defer tx.Rollback()
rows, err := tx.Stmt(stmtCategoryGetAll).Query()
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var category mindflow.Category
if err = rows.Scan(&category.ID, &category.Name); err != nil {
return nil, err
}
categories = append(categories, category)
}
tx.Commit()
return categories, nil
}
func (s *SQLiteMindflow) Close() error { func (s *SQLiteMindflow) Close() error {
stmtCategoryGetAll.Close() stmtCategoryGetAll.Close()
stmtCategoryNew.Close() stmtCategoryNew.Close()