31 lines
1006 B
Go
31 lines
1006 B
Go
package db
|
|
|
|
import (
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/db/account"
|
|
mongoimpl "git.sendico.io/tech/sxchnge/bff/pkg/db/internal/mongo"
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/db/transaction"
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/merrors"
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/mlogger"
|
|
)
|
|
|
|
// Factory exposes high-level repositories used by application services.
|
|
type Factory interface {
|
|
NewAccountDB() (account.DB, error)
|
|
NewAccountDBWithCollection(collection string) (account.DB, error)
|
|
|
|
TransactionFactory() transaction.Factory
|
|
|
|
CloseConnection()
|
|
}
|
|
|
|
// NewConnection builds a Factory backed by the configured driver.
|
|
func NewConnection(logger mlogger.Logger, config *Config) (Factory, error) {
|
|
if config == nil {
|
|
return nil, merrors.InvalidArgument("database configuration is required", "config")
|
|
}
|
|
if config.Driver == Mongo {
|
|
return mongoimpl.NewConnection(logger, config.Settings)
|
|
}
|
|
return nil, merrors.InvalidArgument("unknown database driver: "+string(config.Driver), "config.driver")
|
|
}
|