Skip to content

Commit

Permalink
add sqlite specific BeginTX and NewDB
Browse files Browse the repository at this point in the history
  • Loading branch information
arzonus committed Jan 27, 2025
1 parent 66adf2a commit 79a30d0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
package sqlite

import (
"context"

"github.com/jmoiron/sqlx"
"github.com/uber/cadence/common/persistence/sql/sqlplugin"
"github.com/uber/cadence/common/persistence/sql/sqlplugin/mysql"
)
Expand All @@ -40,7 +43,26 @@ type DB struct {
*mysql.DB
}

// NewDB returns an instance of DB, which contains a new created mysql.DB with sqlite specific methods
func NewDB(xdbs []*sqlx.DB, tx *sqlx.Tx, dbShardID int, numDBShards int) (*DB, error) {
mysqlDB, err := mysql.NewDB(xdbs, tx, dbShardID, numDBShards, newConverter())
if err != nil {
return nil, err
}
return &DB{DB: mysqlDB}, nil
}

// PluginName returns the name of the plugin
func (mdb *DB) PluginName() string {
return PluginName
}

// BeginTX starts a new transaction and returns a new Tx
func (mdb *DB) BeginTX(ctx context.Context, dbShardID int) (sqlplugin.Tx, error) {
mysqlDB, err := mdb.BeginTx(ctx, dbShardID)
if err != nil {
return nil, err
}

return &DB{DB: mysqlDB.(*mysql.DB)}, nil
}

0 comments on commit 79a30d0

Please sign in to comment.