Added Close() method to Mindflow DB. Constructor renamed to New().
This commit is contained in:
parent
0864526393
commit
354c1b01f7
@ -95,10 +95,11 @@ func main() {
|
|||||||
srv.PATCH("/api/guestbook/:id/reply", guestbookApi.EditReply)
|
srv.PATCH("/api/guestbook/:id/reply", guestbookApi.EditReply)
|
||||||
srv.DELETE("/api/guestbook/:id/reply", guestbookApi.DeleteReply)
|
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 {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
defer mindflowDB.Close()
|
||||||
|
|
||||||
mindflowApi := http.NewMindflowApiHandlers(mindflowDB)
|
mindflowApi := http.NewMindflowApiHandlers(mindflowDB)
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ type SQLiteMindflow struct {
|
|||||||
db *sql.DB
|
db *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSQLiteMindflow(path string) (mindflow.Mindflow, error) {
|
func New(path string) (mindflow.Mindflow, error) {
|
||||||
db, err := sql.Open("sqlite3", dsn(path))
|
db, err := sql.Open("sqlite3", dsn(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -225,3 +225,14 @@ func (s *SQLiteMindflow) GetCategoryByID(id int64) (name string, err error) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SQLiteMindflow) Close() error {
|
||||||
|
stmtCategoryById.Close()
|
||||||
|
stmtCategoryNew.Close()
|
||||||
|
stmtPostDelete.Close()
|
||||||
|
stmtPostEdit.Close()
|
||||||
|
stmtPostGetAll.Close()
|
||||||
|
stmtPostNew.Close()
|
||||||
|
|
||||||
|
return s.db.Close()
|
||||||
|
}
|
||||||
|
@ -7,4 +7,5 @@ type Mindflow interface {
|
|||||||
GetAll() ([]Post, error)
|
GetAll() ([]Post, error)
|
||||||
NewCategory(name string) (int64, error)
|
NewCategory(name string) (int64, error)
|
||||||
GetCategoryByID(id int64) (string, error)
|
GetCategoryByID(id int64) (string, error)
|
||||||
|
Close() error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user