27 lines
853 B
Go
27 lines
853 B
Go
package db
|
|
|
|
import (
|
|
mongoimpl "git.sendico.io/tech/sxchnge/shared/database/internal/mongo"
|
|
"git.sendico.io/tech/sxchnge/shared/database/transaction"
|
|
"git.sendico.io/tech/sxchnge/shared/errors"
|
|
"git.sendico.io/tech/sxchnge/shared/logging"
|
|
)
|
|
|
|
// Factory exposes the local connection and transaction lifecycle.
|
|
type Factory interface {
|
|
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")
|
|
}
|