pkg/persistence refactoring
This commit is contained in:
parent
0a497e8fea
commit
8a9b95300a
@ -10,6 +10,8 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var NotImplementedError = errors.New("Function not implemented")
|
||||
|
||||
type Database interface {
|
||||
Engine() databaseEngine
|
||||
DoesTorrentExist(infoHash []byte) (bool, error)
|
||||
@ -59,8 +61,8 @@ const (
|
||||
type databaseEngine uint8
|
||||
|
||||
const (
|
||||
Sqlite3 databaseEngine = 1
|
||||
Postgres databaseEngine = 2
|
||||
Sqlite3 databaseEngine = iota + 1
|
||||
Postgres
|
||||
Stdout
|
||||
)
|
||||
|
||||
|
@ -197,11 +197,7 @@ func (db *postgresDatabase) QueryTorrents(
|
||||
lastOrderedValue *float64,
|
||||
lastID *uint64,
|
||||
) ([]TorrentMetadata, error) {
|
||||
err := fmt.Errorf("QueryTorrents is not supported yet by PostgreSQL backend")
|
||||
|
||||
torrents := make([]TorrentMetadata, 0)
|
||||
|
||||
return torrents, err
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
||||
func (db *postgresDatabase) GetTorrent(infoHash []byte) (*TorrentMetadata, error) {
|
||||
@ -259,7 +255,7 @@ func (db *postgresDatabase) GetFiles(infoHash []byte) ([]File, error) {
|
||||
}
|
||||
|
||||
func (db *postgresDatabase) GetStatistics(from string, n uint) (*Statistics, error) {
|
||||
panic("Not implemented yet for PostgreSQL")
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
||||
func (db *postgresDatabase) setupDatabase() error {
|
||||
|
@ -15,8 +15,6 @@ type out struct {
|
||||
Files []File `json:"files"`
|
||||
}
|
||||
|
||||
var notSupportedError = errors.New("This dummy database engine (\"stdout\") does not support any sort of queries")
|
||||
|
||||
func makeStdoutDatabase(_ *url.URL) (Database, error) {
|
||||
s := new(stdout)
|
||||
s.encoder = json.NewEncoder(os.Stdout)
|
||||
@ -58,7 +56,7 @@ func (s *stdout) Close() error {
|
||||
}
|
||||
|
||||
func (s *stdout) GetNumberOfTorrents() (uint, error) {
|
||||
return 0, notSupportedError
|
||||
return 0, NotImplementedError
|
||||
}
|
||||
|
||||
func (s *stdout) QueryTorrents(
|
||||
@ -70,17 +68,17 @@ func (s *stdout) QueryTorrents(
|
||||
lastOrderedValue *float64,
|
||||
lastID *uint64,
|
||||
) ([]TorrentMetadata, error) {
|
||||
return nil, notSupportedError
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
||||
func (s *stdout) GetTorrent(infoHash []byte) (*TorrentMetadata, error) {
|
||||
return nil, notSupportedError
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
||||
func (s *stdout) GetFiles(infoHash []byte) ([]File, error) {
|
||||
return nil, notSupportedError
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
||||
func (s *stdout) GetStatistics(from string, n uint) (*Statistics, error) {
|
||||
return nil, notSupportedError
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user