35 lines
954 B
Go
35 lines
954 B
Go
package mongo
|
|
|
|
import (
|
|
"git.sendico.io/tech/sxchnge/shared/database"
|
|
"git.sendico.io/tech/sxchnge/shared/database/transaction"
|
|
"git.sendico.io/tech/sxchnge/shared/errors"
|
|
"go.mongodb.org/mongo-driver/v2/mongo"
|
|
)
|
|
|
|
// Dependencies resolves local DB/transaction primitives for edge-local store wiring only.
|
|
type Dependencies struct {
|
|
Database *mongo.Database
|
|
Transactions transaction.Factory
|
|
}
|
|
|
|
type DatabaseProvider interface {
|
|
MongoDatabase() *mongo.Database
|
|
}
|
|
|
|
func ResolveDependencies(dbf db.Factory) (*Dependencies, error) {
|
|
if dbf == nil {
|
|
return nil, merrors.InvalidArgument("database factory is required", "dbFactory")
|
|
}
|
|
|
|
provider, ok := dbf.(DatabaseProvider)
|
|
if !ok || provider.MongoDatabase() == nil {
|
|
return nil, merrors.Internal("mongo database provider is not available for edge-local storage wiring")
|
|
}
|
|
|
|
return &Dependencies{
|
|
Database: provider.MongoDatabase(),
|
|
Transactions: dbf.TransactionFactory(),
|
|
}, nil
|
|
}
|