store

package
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateContact is returned when more than one contacts
	// were found, while at most one was expected.
	ErrDuplicateContact = fmt.Errorf("Duplicate contact")
	// ErrContactNotFound is returned in case a contact was not found.
	ErrContactNotFound = fmt.Errorf("Contact not found")
	// ErrContactAlreadyExists is returned in case the contact
	// already exists when attempting to insert it.
	ErrContactAlreadyExists = fmt.Errorf("Contact already exists")
)
View Source
var (
	// ErrDuplicateDiscussion is returned when more then one discussions
	// were found, while at most one was expected.
	ErrDuplicateDiscussion = fmt.Errorf("Duplicate discussion")
	// ErrDiscussionNotFound is returned in case a discussion was not found.
	ErrDiscussionNotFound = fmt.Errorf("Discussion not found")
	// ErrDiscussionAlreadyExists is returned in case the discussion
	// already exists when attempting to insert it.
	ErrDiscussionAlreadyExists = fmt.Errorf("Discussion already exists")
	// ErrMessageNotFound is returned in case a message id was not found.
	ErrMessageNotFound = fmt.Errorf("Message not found")
	// ErrMessageInvalidDisc is returned in case a message does
	// not belong to a discussion.
	ErrMessageInvalidDisc = fmt.Errorf("Message does not belong to discussion")
)
View Source
var (
	// ErrMaxRetries is returned in case a query conflict
	// could not be resolved after the maximum number of retries.
	ErrMaxRetries = fmt.Errorf("could not resolve transaction conflict after max retries")
)

Functions

func WithBadgerOption

func WithBadgerOption(f func(badger.Options) badger.Options) func(Database)

WithBadgerOption sets a badger option. Useful for passing badger options to badgerhold.

func WithLogger

func WithLogger(logger *slog.Logger) func(Database)

WithLogger sets the database logger.

Types

type AlreadyExistsError

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

func (*AlreadyExistsError) Error

func (e *AlreadyExistsError) Error() string

func (*AlreadyExistsError) Value

func (e *AlreadyExistsError) Value() interface{}

type Database

type Database interface {
	// Contacts
	AddContact(c *model.Contact) (contact *model.Contact, err error)
	GetContact(address string) (*model.Contact, error)
	GetContactByID(uid uint64) (*model.Contact, error)
	RemoveContact(address string) (*model.Contact, error)
	RemoveContactByID(uid uint64) (*model.Contact, error)
	GetContacts() ([]model.Contact, error)

	// Discussions
	AddDiscussion(disc *model.Discussion) (discussion *model.Discussion, err error)
	GetDiscussion(uid uint64) (*model.Discussion, error)
	GetDiscussionByParticipants(participants []string) (*model.Discussion, error)
	RemoveDiscussion(uid uint64) (*model.Discussion, error)
	GetDiscussions(seekIndex, pageSize uint64) ([]model.Discussion, error)
	UpdateDiscussionLastRead(uid uint64, readMsgID uint64) error

	// Invoices-Payments
	AddInvoice(inv *model.Invoice) error
	AddPayments(payments ...*model.Payment) error
	GetLastInvoiceIndex() (invSettleIndex uint64, err error)
	GetLastPaymentIndex() (paymentIndex uint64, err error)
	GetInvoices(pageOpts model.PageOptions) ([]*model.Invoice, error)
	GetPayments(pageOpts model.PageOptions) ([]*model.Payment, error)
	AddRawMessage(*model.RawMessage) error
	GetMessages(discussionUID uint64,
		pageOpts model.PageOptions) ([]model.MessageAggregate, error)

	// Close closes the database
	Close() error
}

Database provices the generic interface for database operations.

func New

func New(dbDir string, options ...func(Database)) (Database, error)

New opens and returns a database object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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