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.

40 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. Files() repositories.FileRepository
  24. Close(ctx context.Context) error
  25. }
  26. // Init sets up the database.
  27. func Init(config config.Database) (Database, error) {
  28. switch config.Driver {
  29. case "mongo", "mgo", "mongodb":
  30. return mongodb.Init(config)
  31. default:
  32. return nil, ErrDriverUnrecognized
  33. }
  34. }