persistence

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimestampLength   = 8
	HashLength        = 32
	DigestLength      = HashLength
	PubsubTopicLength = HashLength
	DBKeyLength       = TimestampLength + PubsubTopicLength + DigestLength
)
View Source
const WALMode = "wal"

WALMode for sqlite.

Variables

View Source
var (
	// ErrInvalidByteSize is returned when DBKey can't be created
	// from a byte slice because it has invalid length.
	ErrInvalidByteSize = errors.New("byte slice has invalid length")
)
View Source
var ErrInvalidCursor = errors.New("invalid cursor")

Functions

This section is empty.

Types

type DBKey added in v0.1.0

type DBKey struct {
	// contains filtered or unexported fields
}

DBKey key to be stored in a db.

func NewDBKey added in v0.1.0

func NewDBKey(timestamp uint64, pubsubTopic string, digest []byte) *DBKey

NewDBKey creates a new DBKey with the given values.

func (*DBKey) Bytes added in v0.1.0

func (k *DBKey) Bytes() []byte

Bytes returns a bytes representation of the DBKey.

func (*DBKey) Digest added in v0.1.0

func (k *DBKey) Digest() []byte

type DBOption

type DBOption func(*DBStore) error

DBOption is an optional setting that can be used to configure the DBStore

func DefaultOptions added in v0.2.0

func DefaultOptions() []DBOption

func WithDB

func WithDB(db *sql.DB) DBOption

WithDB is a DBOption that lets you use any custom *sql.DB with a DBStore.

func WithDriver

func WithDriver(driverName string, datasourceName string) DBOption

WithDriver is a DBOption that will open a *sql.DB connection

func WithMigrationsEnabled added in v0.2.0

func WithMigrationsEnabled(enabled bool) DBOption

WithMigrationsEnabled is a DBOption used to determine whether migrations should be executed or not

func WithRetentionPolicy

func WithRetentionPolicy(maxMessages int, maxDuration time.Duration) DBOption

WithRetentionPolicy is a DBOption that specifies the max number of messages to be stored and duration before they're removed from the message store

type DBStore

type DBStore struct {
	MessageProvider
	// contains filtered or unexported fields
}

DBStore is a MessageProvider that has a *sql.DB connection

func NewDBStore

func NewDBStore(log *zap.Logger, options ...DBOption) (*DBStore, error)

Creates a new DB store using the db specified via options. It will create a messages table if it does not exist and clean up records according to the retention policy used

func (*DBStore) Count added in v0.2.0

func (d *DBStore) Count() (int, error)

Count returns the number of rows in the message table

func (*DBStore) GetAll

func (d *DBStore) GetAll() ([]StoredMessage, error)

GetAll returns all the stored WakuMessages

func (*DBStore) GetStoredMessage added in v0.1.0

func (d *DBStore) GetStoredMessage(row *sql.Rows) (StoredMessage, error)

GetStoredMessage is a helper function used to convert a `*sql.Rows` into a `StoredMessage`

func (*DBStore) MostRecentTimestamp added in v0.1.0

func (d *DBStore) MostRecentTimestamp() (int64, error)

MostRecentTimestamp returns an unix timestamp with the most recent senderTimestamp in the message table

func (*DBStore) Put

func (d *DBStore) Put(env *protocol.Envelope) error

Put inserts a WakuMessage into the DB

func (*DBStore) Query added in v0.1.0

func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, error)

Query retrieves messages from the DB

func (*DBStore) Stop

func (d *DBStore) Stop()

Stop closes a DB connection

type Hash added in v0.1.0

type Hash [HashLength]byte

type MessageProvider

type MessageProvider interface {
	GetAll() ([]StoredMessage, error)
	Put(env *protocol.Envelope) error
	Query(query *pb.HistoryQuery) ([]StoredMessage, error)
	MostRecentTimestamp() (int64, error)
	Stop()
}

type RendezVousLevelDB

type RendezVousLevelDB struct {
	// contains filtered or unexported fields
}

RendezVousLevelDB is a struct used to hold a reference to a LevelDB database

func NewRendezVousLevelDB

func NewRendezVousLevelDB(dBPath string) (*RendezVousLevelDB, error)

NewRendezVousLevelDB opens a LevelDB database to be used for rendezvous protocol

func (*RendezVousLevelDB) Delete

func (r *RendezVousLevelDB) Delete(key []byte) error

Delete removes a key from the database

func (*RendezVousLevelDB) NewIterator

func (r *RendezVousLevelDB) NewIterator(prefix []byte) rendezvous.Iterator

NewIterator returns an interator that can be used to iterate over all the records contained in the DB

func (*RendezVousLevelDB) Put

func (r *RendezVousLevelDB) Put(key []byte, value []byte) error

Put inserts or updates a key in the database

type StoredMessage

type StoredMessage struct {
	ID           []byte
	PubsubTopic  string
	ReceiverTime int64
	Message      *pb.WakuMessage
}

Directories

Path Synopsis
sql

Jump to

Keyboard shortcuts

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