Skip to content

Commit

Permalink
sql: make it easy to support heterogeneous SQL databases (uber#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkat1109 authored Feb 1, 2019
1 parent 0dad9eb commit 78d84ea
Show file tree
Hide file tree
Showing 23 changed files with 3,389 additions and 2,126 deletions.
8 changes: 4 additions & 4 deletions common/persistence/sql/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
"fmt"

"github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/uber-common/bark"
workflow "github.com/uber/cadence/.gen/go/shared"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/sql/storage/sqldb"
)

// TODO: Rename all SQL Managers to Stores
type sqlStore struct {
db *sqlx.DB
db sqldb.Interface
logger bark.Logger
}

Expand All @@ -49,8 +49,8 @@ func (m *sqlStore) Close() {
}
}

func (m *sqlStore) txExecute(operation string, f func(tx *sqlx.Tx) error) error {
tx, err := m.db.Beginx()
func (m *sqlStore) txExecute(operation string, f func(tx sqldb.Tx) error) error {
tx, err := m.db.BeginTx()
if err != nil {
return &workflow.InternalServiceError{
Message: fmt.Sprintf("%s failed. Failed to start transaction. Error: %v", operation, err),
Expand Down
7 changes: 4 additions & 3 deletions common/persistence/sql/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
"fmt"
"sync"

"github.com/jmoiron/sqlx"
"github.com/uber-common/bark"
p "github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/sql/storage"
"github.com/uber/cadence/common/persistence/sql/storage/sqldb"
"github.com/uber/cadence/common/service/config"
)

Expand All @@ -40,7 +41,7 @@ type (
execStoreFactory *executionStoreFactory
}
executionStoreFactory struct {
db *sqlx.DB
db sqldb.Interface
logger bark.Logger
}
)
Expand Down Expand Up @@ -128,7 +129,7 @@ func (f *Factory) newExecutionStoreFactory() (*executionStoreFactory, error) {
}

func newExecutionStoreFactory(cfg config.SQL, logger bark.Logger) (*executionStoreFactory, error) {
db, err := newConnection(cfg)
db, err := storage.NewSQLDB(&cfg)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 78d84ea

Please sign in to comment.