lowlevel.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2018 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package db
  7. import (
  8. "github.com/syncthing/syncthing/lib/db/backend"
  9. )
  10. // Lowlevel is the lowest level database interface. It has a very simple
  11. // purpose: hold the actual backend database, and the in-memory state
  12. // that belong to that database. In the same way that a single on disk
  13. // database can only be opened once, there should be only one Lowlevel for
  14. // any given backend.
  15. type Lowlevel struct {
  16. backend.Backend
  17. folderIdx *smallIndex
  18. deviceIdx *smallIndex
  19. }
  20. // NewLowlevel wraps the given *leveldb.DB into a *lowlevel
  21. func NewLowlevel(db backend.Backend) *Lowlevel {
  22. return &Lowlevel{
  23. Backend: db,
  24. folderIdx: newSmallIndex(db, []byte{KeyTypeFolderIdx}),
  25. deviceIdx: newSmallIndex(db, []byte{KeyTypeDeviceIdx}),
  26. }
  27. }
  28. // ListFolders returns the list of folders currently in the database
  29. func (db *Lowlevel) ListFolders() []string {
  30. return db.folderIdx.Values()
  31. }