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.

39 lines
1.1 KiB

  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. Stories() repositories.StoryRepository
  19. Chapters() repositories.ChapterRepository
  20. Comments() repositories.CommentRepository
  21. Keys() repositories.KeyRepository
  22. Users() repositories.UserRepository
  23. Close(ctx context.Context) error
  24. }
  25. // Init sets up the database.
  26. func Init(config config.Database) (Database, error) {
  27. switch config.Driver {
  28. case "mongo", "mgo", "mongodb":
  29. return mongodb.Init(config)
  30. default:
  31. return nil, ErrDriverUnrecognized
  32. }
  33. }