GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
764 B

  1. package database
  2. import (
  3. "context"
  4. "errors"
  5. "git.aiterp.net/rpdata/api/database/mongodb"
  6. "git.aiterp.net/rpdata/api/internal/config"
  7. "git.aiterp.net/rpdata/api/repositories"
  8. )
  9. // ErrDriverUnrecognized is returned if the driver is not recognized
  10. var ErrDriverUnrecognized = errors.New("Driver not recognized, check your config or update rpdata")
  11. type Database interface {
  12. Changes() repositories.ChangeRepository
  13. Characters() repositories.CharacterRepository
  14. Tags() repositories.TagRepository
  15. Close(ctx context.Context) error
  16. }
  17. // Init sets up the database.
  18. func Init(config config.Database) (Database, error) {
  19. switch config.Driver {
  20. case "mongo", "mgo", "mongodb":
  21. return mongodb.Init(config)
  22. default:
  23. return nil, ErrDriverUnrecognized
  24. }
  25. }