1
0

Added Close() method to Mindflow DB. Constructor renamed to New().

This commit is contained in:
Alexander Andreev 2023-05-14 20:17:30 +04:00
parent 0864526393
commit 354c1b01f7
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 15 additions and 2 deletions

View File

@ -95,10 +95,11 @@ func main() {
srv.PATCH("/api/guestbook/:id/reply", guestbookApi.EditReply)
srv.DELETE("/api/guestbook/:id/reply", guestbookApi.DeleteReply)
mindflowDB, err := mfsqlite.NewSQLiteMindflow(path.Join(*databasesPath, "mindflow.sqlite"))
mindflowDB, err := mfsqlite.New(path.Join(*databasesPath, "mindflow.sqlite"))
if err != nil {
log.Fatalln(err)
}
defer mindflowDB.Close()
mindflowApi := http.NewMindflowApiHandlers(mindflowDB)

View File

@ -82,7 +82,7 @@ type SQLiteMindflow struct {
db *sql.DB
}
func NewSQLiteMindflow(path string) (mindflow.Mindflow, error) {
func New(path string) (mindflow.Mindflow, error) {
db, err := sql.Open("sqlite3", dsn(path))
if err != nil {
return nil, err
@ -225,3 +225,14 @@ func (s *SQLiteMindflow) GetCategoryByID(id int64) (name string, err error) {
return
}
func (s *SQLiteMindflow) Close() error {
stmtCategoryById.Close()
stmtCategoryNew.Close()
stmtPostDelete.Close()
stmtPostEdit.Close()
stmtPostGetAll.Close()
stmtPostNew.Close()
return s.db.Close()
}

View File

@ -7,4 +7,5 @@ type Mindflow interface {
GetAll() ([]Post, error)
NewCategory(name string) (int64, error)
GetCategoryByID(id int64) (string, error)
Close() error
}