no_database.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright 2021 gorse Project Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package data
  15. import (
  16. "context"
  17. "time"
  18. )
  19. // NoDatabase means that no database used.
  20. type NoDatabase struct{}
  21. // Init method of NoDatabase returns ErrNoDatabase.
  22. func (NoDatabase) Init() error {
  23. return ErrNoDatabase
  24. }
  25. func (NoDatabase) Ping() error {
  26. return ErrNoDatabase
  27. }
  28. // Close method of NoDatabase returns ErrNoDatabase.
  29. func (NoDatabase) Close() error {
  30. return ErrNoDatabase
  31. }
  32. func (NoDatabase) Purge() error {
  33. return ErrNoDatabase
  34. }
  35. // BatchInsertItems method of NoDatabase returns ErrNoDatabase.
  36. func (NoDatabase) BatchInsertItems(_ context.Context, _ []Item) error {
  37. return ErrNoDatabase
  38. }
  39. // BatchGetItems method of NoDatabase returns ErrNoDatabase.
  40. func (NoDatabase) BatchGetItems(_ context.Context, _ []string) ([]Item, error) {
  41. return nil, ErrNoDatabase
  42. }
  43. // DeleteItem method of NoDatabase returns ErrNoDatabase.
  44. func (NoDatabase) DeleteItem(_ context.Context, _ string) error {
  45. return ErrNoDatabase
  46. }
  47. // GetItem method of NoDatabase returns ErrNoDatabase.
  48. func (NoDatabase) GetItem(_ context.Context, _ string) (Item, error) {
  49. return Item{}, ErrNoDatabase
  50. }
  51. // GetItems method of NoDatabase returns ErrNoDatabase.
  52. func (NoDatabase) GetItems(_ context.Context, _ string, _ int, _ *time.Time) (string, []Item, error) {
  53. return "", nil, ErrNoDatabase
  54. }
  55. // GetItemStream method of NoDatabase returns ErrNoDatabase.
  56. func (NoDatabase) GetItemStream(_ context.Context, _ int, _ *time.Time) (chan []Item, chan error) {
  57. itemChan := make(chan []Item, bufSize)
  58. errChan := make(chan error, 1)
  59. go func() {
  60. defer close(itemChan)
  61. defer close(errChan)
  62. errChan <- ErrNoDatabase
  63. }()
  64. return itemChan, errChan
  65. }
  66. // GetItemFeedback method of NoDatabase returns ErrNoDatabase.
  67. func (NoDatabase) GetItemFeedback(_ context.Context, _ string, _ ...string) ([]Feedback, error) {
  68. return nil, ErrNoDatabase
  69. }
  70. // BatchInsertUsers method of NoDatabase returns ErrNoDatabase.
  71. func (NoDatabase) BatchInsertUsers(_ context.Context, _ []User) error {
  72. return ErrNoDatabase
  73. }
  74. // DeleteUser method of NoDatabase returns ErrNoDatabase.
  75. func (NoDatabase) DeleteUser(_ context.Context, _ string) error {
  76. return ErrNoDatabase
  77. }
  78. // GetUser method of NoDatabase returns ErrNoDatabase.
  79. func (NoDatabase) GetUser(_ context.Context, _ string) (User, error) {
  80. return User{}, ErrNoDatabase
  81. }
  82. // GetUsers method of NoDatabase returns ErrNoDatabase.
  83. func (NoDatabase) GetUsers(_ context.Context, _ string, _ int) (string, []User, error) {
  84. return "", nil, ErrNoDatabase
  85. }
  86. // GetUserStream method of NoDatabase returns ErrNoDatabase.
  87. func (NoDatabase) GetUserStream(_ context.Context, _ int) (chan []User, chan error) {
  88. userChan := make(chan []User, bufSize)
  89. errChan := make(chan error, 1)
  90. go func() {
  91. defer close(userChan)
  92. defer close(errChan)
  93. errChan <- ErrNoDatabase
  94. }()
  95. return userChan, errChan
  96. }
  97. // GetUserFeedback method of NoDatabase returns ErrNoDatabase.
  98. func (NoDatabase) GetUserFeedback(_ context.Context, _ string, _ *time.Time, _ ...string) ([]Feedback, error) {
  99. return nil, ErrNoDatabase
  100. }
  101. // GetUserItemFeedback method of NoDatabase returns ErrNoDatabase.
  102. func (NoDatabase) GetUserItemFeedback(_ context.Context, _, _ string, _ ...string) ([]Feedback, error) {
  103. return nil, ErrNoDatabase
  104. }
  105. // DeleteUserItemFeedback method of NoDatabase returns ErrNoDatabase.
  106. func (NoDatabase) DeleteUserItemFeedback(_ context.Context, _, _ string, _ ...string) (int, error) {
  107. return 0, ErrNoDatabase
  108. }
  109. // BatchInsertFeedback method of NoDatabase returns ErrNoDatabase.
  110. func (NoDatabase) BatchInsertFeedback(_ context.Context, _ []Feedback, _, _, _ bool) error {
  111. return ErrNoDatabase
  112. }
  113. // GetFeedback method of NoDatabase returns ErrNoDatabase.
  114. func (NoDatabase) GetFeedback(_ context.Context, _ string, _ int, _, _ *time.Time, _ ...string) (string, []Feedback, error) {
  115. return "", nil, ErrNoDatabase
  116. }
  117. // GetFeedbackStream method of NoDatabase returns ErrNoDatabase.
  118. func (NoDatabase) GetFeedbackStream(_ context.Context, _ int, _ ...ScanOption) (chan []Feedback, chan error) {
  119. feedbackChan := make(chan []Feedback, bufSize)
  120. errChan := make(chan error, 1)
  121. go func() {
  122. defer close(feedbackChan)
  123. defer close(errChan)
  124. errChan <- ErrNoDatabase
  125. }()
  126. return feedbackChan, errChan
  127. }
  128. func (d NoDatabase) ModifyItem(_ context.Context, _ string, _ ItemPatch) error {
  129. return ErrNoDatabase
  130. }
  131. func (d NoDatabase) ModifyUser(_ context.Context, _ string, _ UserPatch) error {
  132. return ErrNoDatabase
  133. }