Skip to content

Commit

Permalink
try cancelable context
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Wei authored and Allan Wei committed Oct 31, 2018
1 parent b6391e2 commit 0bebf8c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (

//DBcon ... Project DB type
type DBcon struct {
DB *sql.DB
Ctx context.Context
Qstmt *sql.Stmt
DB *sql.DB
Ctx context.Context
Qstmt *sql.Stmt
cancel context.CancelFunc
}

//ExecuteResult ...
Expand Down Expand Up @@ -92,12 +93,15 @@ func (c *DBcon) GetResultRows(sqlquery string) (*sql.Rows, error) {
return rows, nil

}

//Close ... Close dbConntions
func (c *DBcon) Close(){
c.DB.Close()
c.Ctx.Done()
func (c *DBcon) Close() {
c.Qstmt.Close()
c.DB.Close()
c.cancel()

}

//CreateDBCon ... Create Project DB Connection
func CreateDBCon(dbconnectionstring *string) (*DBcon, error) {
var cs string
Expand Down Expand Up @@ -129,6 +133,9 @@ func CreateDBCon(dbconnectionstring *string) (*DBcon, error) {
return nil, err

}
c := DBcon{DB: db, Ctx: context.TODO()}
c := DBcon{}
c.DB = db
c.Ctx, c.cancel = context.WithCancel(context.Background())
//c := DBcon{DB: db, Ctx: context.TODO()}
return &c, nil
}

0 comments on commit 0bebf8c

Please sign in to comment.