1
0

There is no need in DeleteUnusedCategories() so let's get rid of it.

This commit is contained in:
Alexander Andreev 2023-05-23 04:29:06 +04:00
parent f1d6f5c736
commit ca51617f0e
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 8 additions and 39 deletions

View File

@ -22,8 +22,6 @@ var (
queryCategoryEdit string
//go:embed queries/categoryDelete.sql
queryCategoryDelete string
//go:embed queries/categoryDeleteUnused.sql
queryCategoryDeleteUnused string
//go:embed queries/postGetAll.sql
queryPostGetAll string
//go:embed queries/postNew.sql
@ -35,15 +33,14 @@ var (
)
var (
stmtCategoryGetAll *sql.Stmt
stmtCategoryNew *sql.Stmt
stmtCategoryEdit *sql.Stmt
stmtCategoryDelete *sql.Stmt
stmtCategoryDeleteUnused *sql.Stmt
stmtPostGetAll *sql.Stmt
stmtPostNew *sql.Stmt
stmtPostEdit *sql.Stmt
stmtPostDelete *sql.Stmt
stmtCategoryGetAll *sql.Stmt
stmtCategoryNew *sql.Stmt
stmtCategoryEdit *sql.Stmt
stmtCategoryDelete *sql.Stmt
stmtPostGetAll *sql.Stmt
stmtPostNew *sql.Stmt
stmtPostEdit *sql.Stmt
stmtPostDelete *sql.Stmt
)
func initDBStatements(db *sql.DB) error {
@ -74,11 +71,6 @@ func initDBStatements(db *sql.DB) error {
return errors.Wrap(err, "failed to prepare queryCategoryDelete")
}
stmtCategoryDeleteUnused, err = db.Prepare(queryCategoryDeleteUnused)
if err != nil {
return errors.Wrap(err, "failed to prepare queryCategoryDeleteUnused")
}
stmtPostGetAll, err = db.Prepare(queryPostGetAll)
if err != nil {
return errors.Wrap(err, "failed to prepare queryPostGetAll")
@ -292,22 +284,6 @@ func (s *SQLiteMindflow) DeleteCategory(id int64) (err error) {
return nil
}
func (s *SQLiteMindflow) DeleteUnusedCategories() (err error) {
tx, err := s.db.Begin()
if err != nil {
return err
}
defer tx.Rollback()
if _, err = tx.Stmt(stmtCategoryDeleteUnused).Exec(); err != nil {
return err
}
tx.Commit()
return nil
}
func (s *SQLiteMindflow) Close() error {
stmtCategoryGetAll.Close()
stmtCategoryNew.Close()

View File

@ -1,6 +0,0 @@
DELETE FROM `category`
WHERE `category`.`category_id` NOT IN (
SELECT `category_id`
FROM `post`
GROUP BY `post`.`category_id`
HAVING COUNT(`post`.`post_id`) > 0 );

View File

@ -52,7 +52,6 @@ type Mindflow interface {
NewCategory(category *Category) (int64, error)
EditCategory(category *Category) error
DeleteCategory(id int64) error
DeleteUnusedCategories() error
Categories() ([]Category, error)
Close() error
}