Skip to content

Commit

Permalink
close db when insert finished (#714)
Browse files Browse the repository at this point in the history
* close db when insert finished

* use defer instead of return db.close

---------

Co-authored-by: 李毓琪 <[email protected]>
  • Loading branch information
rhoninl and 李毓琪 authored Sep 22, 2023
1 parent 5a19f6b commit 42820bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/telemetryservice/sql/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (db *DBHelper) SendToDB(ctx context.Context, deviceName string, rawData []b
return err
}

defer db.DB.Close()

err = db.InsertDataToDB(ctx, deviceName, rawData)
if err != nil {
logger.Errorf("Error to Insert rawData to DB, errror: %v", err.Error())
Expand Down
2 changes: 2 additions & 0 deletions pkg/telemetryservice/sql/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (db *DBHelper) SendToDB(ctx context.Context, deviceName string, rawData []b
return err
}

defer db.DB.Close()

err = db.InsertDataToDB(ctx, deviceName, rawData)
if err != nil {
logger.Errorf("Error to Insert rawData to DB, errror: %v", err.Error())
Expand Down
2 changes: 2 additions & 0 deletions pkg/telemetryservice/sql/tdengine/tdengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (db *DBHelper) SendToDB(ctx context.Context, deviceName string, rawData []b
return err
}

defer db.DB.Close()

err = db.InsertDataToDB(ctx, deviceName, rawData)
if err != nil {
logger.Errorf("Error to Insert rawData to DB, errror: %v", err.Error())
Expand Down

0 comments on commit 42820bf

Please sign in to comment.