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.

34 lines
890 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 installed version or your configuration")
  11. type Database interface {
  12. Changes() repositories.ChangeRepository
  13. Channels() repositories.ChannelRepository
  14. Characters() repositories.CharacterRepository
  15. Tags() repositories.TagRepository
  16. Logs() repositories.LogRepository
  17. Posts() repositories.PostRepository
  18. Close(ctx context.Context) error
  19. }
  20. // Init sets up the database.
  21. func Init(config config.Database) (Database, error) {
  22. switch config.Driver {
  23. case "mongo", "mgo", "mongodb":
  24. return mongodb.Init(config)
  25. default:
  26. return nil, ErrDriverUnrecognized
  27. }
  28. }