From 5ef41d5961a1e6504558d94c2071a957d274d762 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 14 May 2023 03:52:07 +0400 Subject: [PATCH] Implemented NewCategory() method. --- pkg/mindflow/database/sqlite/db.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/mindflow/database/sqlite/db.go b/pkg/mindflow/database/sqlite/db.go index b73f1be..7a3a8bc 100644 --- a/pkg/mindflow/database/sqlite/db.go +++ b/pkg/mindflow/database/sqlite/db.go @@ -182,3 +182,29 @@ func (s *SQLiteMindflow) GetAll() (posts []mindflow.Post, err error) { defer tx.Rollback() return nil, nil } + +func (s *SQLiteMindflow) NewCategory(name string) (int64, error) { + tx, err := s.db.Begin() + if err != nil { + return 0, err + } + defer tx.Rollback() + + r, err := tx.Stmt(stmtPostNew).Exec(name) + if err != nil { + return 0, err + } + + id, err := r.LastInsertId() + if err != nil { + return 0, err + } + + tx.Commit() + + return id, nil +} + +func (s *SQLiteMindflow) GetCategoryByID(id int64) (string, error) { + return "", nil +}