github.com/safing/portbase@v0.19.5/database/storage/sinkhole/sinkhole.go (about) 1 package sinkhole 2 3 import ( 4 "context" 5 "errors" 6 "time" 7 8 "github.com/safing/portbase/database/iterator" 9 "github.com/safing/portbase/database/query" 10 "github.com/safing/portbase/database/record" 11 "github.com/safing/portbase/database/storage" 12 ) 13 14 // Sinkhole is a dummy storage. 15 type Sinkhole struct { 16 name string 17 } 18 19 var ( 20 // Compile time interface checks. 21 _ storage.Interface = &Sinkhole{} 22 _ storage.Maintainer = &Sinkhole{} 23 _ storage.Batcher = &Sinkhole{} 24 ) 25 26 func init() { 27 _ = storage.Register("sinkhole", NewSinkhole) 28 } 29 30 // NewSinkhole creates a dummy database. 31 func NewSinkhole(name, location string) (storage.Interface, error) { 32 return &Sinkhole{ 33 name: name, 34 }, nil 35 } 36 37 // Exists returns whether an entry with the given key exists. 38 func (s *Sinkhole) Exists(key string) (bool, error) { 39 return false, nil 40 } 41 42 // Get returns a database record. 43 func (s *Sinkhole) Get(key string) (record.Record, error) { 44 return nil, storage.ErrNotFound 45 } 46 47 // GetMeta returns the metadata of a database record. 48 func (s *Sinkhole) GetMeta(key string) (*record.Meta, error) { 49 return nil, storage.ErrNotFound 50 } 51 52 // Put stores a record in the database. 53 func (s *Sinkhole) Put(r record.Record) (record.Record, error) { 54 return r, nil 55 } 56 57 // PutMany stores many records in the database. 58 func (s *Sinkhole) PutMany(shadowDelete bool) (chan<- record.Record, <-chan error) { 59 batch := make(chan record.Record, 100) 60 errs := make(chan error, 1) 61 62 // start handler 63 go func() { 64 for range batch { 65 // discard everything 66 } 67 errs <- nil 68 }() 69 70 return batch, errs 71 } 72 73 // Delete deletes a record from the database. 74 func (s *Sinkhole) Delete(key string) error { 75 return nil 76 } 77 78 // Query returns a an iterator for the supplied query. 79 func (s *Sinkhole) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error) { 80 return nil, errors.New("query not implemented by sinkhole") 81 } 82 83 // ReadOnly returns whether the database is read only. 84 func (s *Sinkhole) ReadOnly() bool { 85 return false 86 } 87 88 // Injected returns whether the database is injected. 89 func (s *Sinkhole) Injected() bool { 90 return false 91 } 92 93 // Maintain runs a light maintenance operation on the database. 94 func (s *Sinkhole) Maintain(ctx context.Context) error { 95 return nil 96 } 97 98 // MaintainThorough runs a thorough maintenance operation on the database. 99 func (s *Sinkhole) MaintainThorough(ctx context.Context) error { 100 return nil 101 } 102 103 // MaintainRecordStates maintains records states in the database. 104 func (s *Sinkhole) MaintainRecordStates(ctx context.Context, purgeDeletedBefore time.Time, shadowDelete bool) error { 105 return nil 106 } 107 108 // Shutdown shuts down the database. 109 func (s *Sinkhole) Shutdown() error { 110 return nil 111 }