database

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2025 License: Unlicense Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateIdHashFromData

func CreateIdHashFromData(data []byte) (i *types2.IdHash, err error)

CreateIdHashFromData creates an IdHash from data that could be hex or binary

func CreatePubHashFromData

func CreatePubHashFromData(data []byte) (p *types2.PubHash, err error)

CreatePubHashFromData creates a PubHash from data that could be hex or binary

func GetIndexesForEvent

func GetIndexesForEvent(ev *event.E, serial uint64) (
	idxs [][]byte, err error,
)

GetIndexesForEvent creates all the indexes for an event.E instance as defined in keys.go. It returns a slice of byte slices that can be used to store the event in the database.

func IsHexString

func IsHexString(data []byte) (isHex bool)

IsHexString checks if the byte slice contains only hex characters

func NewLogger

func NewLogger(logLevel int, label string) (l *logger)

NewLogger creates a new badger logger.

Types

type D

type D struct {
	Logger *logger
	*badger.DB
	// contains filtered or unexported fields
}

func New

func New(ctx context.T, cancel context.F, dataDir, logLevel string) (
	d *D, err error,
)

func (*D) Close

func (d *D) Close() (err error)

Close releases resources and closes the database.

func (*D) DeleteEvent

func (d *D) DeleteEvent(c context.T, eid *eventid.T) (err error)

DeleteEvent removes an event from the database identified by `eid`. If noTombstone is false or not provided, a tombstone is created for the event.

func (*D) EventIdsBySerial

func (d *D) EventIdsBySerial(start uint64, count int) (
	evs []eventidserial.E, err error,
)

func (*D) Export

func (d *D) Export(c context.T, w io.Writer, pubkeys ...[]byte)

func (*D) FetchEventBySerial

func (d *D) FetchEventBySerial(ser *types.Uint40) (ev *event.E, err error)

func (*D) GetFullIdPubkeyBySerial

func (d *D) GetFullIdPubkeyBySerial(ser *types.Uint40) (
	fidpk *store.IdPkTs, err error,
)

func (*D) GetSerialById

func (d *D) GetSerialById(id []byte) (ser *types.Uint40, err error)

func (*D) GetSerialsByRange

func (d *D) GetSerialsByRange(idx Range) (
	sers types.Uint40s, err error,
)

func (*D) Import

func (d *D) Import(r io.Reader)

func (*D) Init

func (d *D) Init(path string) (err error)

Init initializes the database with the given path.

func (*D) Path

func (d *D) Path() string

Path returns the path where the database files are stored.

func (*D) QueryEvents

func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error)

QueryEvents retrieves events based on the provided filter. If the filter contains Ids, it fetches events by those Ids directly, overriding other filter criteria. Otherwise, it queries by other filter criteria and fetches matching events. Results are returned in reverse chronological order of their creation timestamps.

func (*D) QueryForIds

func (d *D) QueryForIds(c context.T, f *filter.F) (
	idPkTs []store.IdPkTs, err error,
)

QueryForIds retrieves a list of IdPkTs based on the provided filter. It supports filtering by ranges and tags but disallows filtering by Ids. Results are sorted by timestamp in reverse chronological order. Returns an error if the filter contains Ids or if any operation fails.

func (*D) QueryForSerials

func (d *D) QueryForSerials(c context.T, f *filter.F) (
	sers types.Uint40s, err error,
)

QueryForSerials takes a filter and returns the serials of events that match, sorted in reverse chronological order.

func (*D) SaveEvent

func (d *D) SaveEvent(c context.T, ev *event.E) (kc, vc int, err error)

SaveEvent saves an event to the database, generating all the necessary indexes.

func (*D) SetLogLevel

func (d *D) SetLogLevel(level string)

func (*D) Sync

func (d *D) Sync() (err error)

Sync flushes the database buffers to disk.

func (*D) Wipe

func (d *D) Wipe() (err error)

type Range

type Range struct {
	Start, End []byte
}

func GetIndexesFromFilter

func GetIndexesFromFilter(f *filter.F) (idxs []Range, err error)

GetIndexesFromFilter returns encoded indexes based on the given filter.

An error is returned if any input values are invalid during encoding.

The indexes are designed so that only one table needs to be iterated, being a complete set of combinations of all fields in the event, thus there is no need to decode events until they are to be delivered.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL