File: database.go

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (75 lines) | stat: -rw-r--r-- 1,537 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Package database provides KV database for meta-information
package database

import "errors"

// Errors for Storage
var (
	ErrNotFound = errors.New("key not found")
)

// StorageProcessor is a function to process one single storage entry
type StorageProcessor func(key []byte, value []byte) error

// Reader provides KV read calls
type Reader interface {
	Get(key []byte) ([]byte, error)
}

// PrefixReader provides prefixed operations
type PrefixReader interface {
	HasPrefix(prefix []byte) bool
	ProcessByPrefix(prefix []byte, proc StorageProcessor) error
	KeysByPrefix(prefix []byte) [][]byte
	FetchByPrefix(prefix []byte) [][]byte
}

// Writer provides KV update/delete calls
type Writer interface {
	Put(key []byte, value []byte) error
	Delete(key []byte) error
}

// ReaderWriter combines Reader and Writer
type ReaderWriter interface {
	Reader
	Writer
}

// Storage is an interface to KV storage
type Storage interface {
	Reader
	Writer

	PrefixReader

	CreateBatch() Batch
	OpenTransaction() (Transaction, error)

	CreateTemporary() (Storage, error)

	Open() error
	Close() error
	CompactDB() error
	Drop() error
}

// Batch provides a way to pack many writes.
type Batch interface {
	Writer

	// Write closes batch and send accumulated writes to the database
	Write() error
}

// Transaction provides isolated atomic way to perform updates.
//
// Transactions might be expensive.
// Transaction should always finish with either Discard() or Commit()
type Transaction interface {
	Reader
	Writer

	Commit() error
	Discard()
}