store

package
v0.20.5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package store provides methods for registering and accessing database adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeUid

func DecodeUid(uid types.Uid) int64

DecodeUid takes an XTEA encrypted Uid and decrypts it into an int64. This is needed for sql compatibility. Tte original int64 values are generated by snowflake which ensures that the top bit is unset.

func EncodeUid

func EncodeUid(id int64) types.Uid

EncodeUid applies XTEA encryption to an int64 value. It's the inverse of DecodeUid.

func GetNewUUid

func GetNewUUid() string

func InitAuthLogicalNames

func InitAuthLogicalNames(config json.RawMessage) error

InitAuthLogicalNames initializes authentication mapping "logical handler name":"actual handler name". Logical name must not be empty, actual name could be an empty string.

func RegisterAdapter

func RegisterAdapter(a adapter.Adapter)

RegisterAdapter makes a persistence adapter available. If Register is called twice or if the adapter is nil, it panics.

func RegisterAuthScheme

func RegisterAuthScheme(name string, handler auth.AuthHandler)

RegisterAuthScheme registers an authentication scheme handler. The 'name' must be the hardcoded name, NOT the logical name.

func RegisterMediaHandler

func RegisterMediaHandler(name string, mh media.Handler)

RegisterMediaHandler saves reference to a media handler (file upload-download handler).

func RegisterValidator

func RegisterValidator(name string, v validate.Validator)

RegisterValidator registers validation scheme.

Types

type DevicePersistenceInterface

type DevicePersistenceInterface interface {
	Update(uid types.Uid, oldDeviceID string, dev *types.DeviceDef) error
	GetAll(uid ...types.Uid) (map[types.Uid][]types.DeviceDef, int, error)
	Delete(uid types.Uid, deviceID string) error
}

DevicePersistenceInterface is an interface which defines methods used for handling device IDs. Mostly used to generate push notifications.

Devices is a singleton instance of DevicePersistenceInterface to map methods to.

type FilePersistenceInterface

type FilePersistenceInterface interface {
	// StartUpload records that the given user initiated a file upload
	StartUpload(fd *types.FileDef) error
	// FinishUpload marks started upload as successfully finished.
	FinishUpload(fd *types.FileDef, success bool, size int64) (*types.FileDef, error)
	// Get fetches a file record for a unique file id.
	Get(fid string) (*types.FileDef, error)
	// DeleteUnused removes unused attachments.
	DeleteUnused(olderThan time.Time, limit int) error
	// LinkAttachments connects earlier uploaded attachments to a message or topic to prevent it
	// from being garbage collected.
	LinkAttachments(topic string, msgId types.Uid, attachments []string) error
}

FilePersistenceInterface is an interface wchich defines methods used for file handling (records or uploaded files).

Files is a sigleton instance of FilePersistenceInterface to be used for handling file uploads.

type FriendsPersistenceInterface

type FriendsPersistenceInterface interface {
	Add(uid *types.Friendcontact) error
	Get(uid types.Uid) error
	Delete(uid types.Uid) error
}

Friends is a singleton ancor object exporting FriendsPersistenceInterface methods.

type MessagesPersistenceInterface

type MessagesPersistenceInterface interface {
	Save(msg *types.Message, attachmentURLs []string, readBySender bool) error
	DeleteList(topic string, delID int, forUser types.Uid, ranges []types.Range) error
	GetAll(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Message, error)
	GetDeleted(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Range, int, error)
}

MessagesPersistenceInterface is an interface which defines methods for persistent storage of messages.

Messages is a singleton ancor object for exporting MessagesPersistenceInterface.

type PersistentStorageInterface

type PersistentStorageInterface interface {
	Open(workerId int, jsonconf json.RawMessage) error
	Close() error
	IsOpen() bool
	GetAdapter() adapter.Adapter
	GetAdapterName() string
	GetAdapterVersion() int
	GetDbVersion() int
	InitDb(jsonconf json.RawMessage, reset bool) error
	UpgradeDb(jsonconf json.RawMessage) error
	GetUid() types.Uid
	GetUidString() string
	DbStats() func() interface{}
	GetAuthNames() []string
	GetAuthHandler(name string) auth.AuthHandler
	GetLogicalAuthHandler(name string) auth.AuthHandler
	GetValidator(name string) validate.Validator
	GetMediaHandler() media.Handler
	UseMediaHandler(name, config string) error
}

PersistentStorageInterface defines methods used for interation with persistent storage.

Store is the main object for interacting with persistent storage.

type SubsPersistenceInterface

type SubsPersistenceInterface interface {
	Create(subs ...*types.Subscription) error
	Get(topic string, user types.Uid, keepDeleted bool) (*types.Subscription, error)
	Update(topic string, user types.Uid, update map[string]interface{}) error
	Delete(topic string, user types.Uid) error
}

SubsPersistenceInterface is an interface which defines methods for persistent storage of subscriptions.

Subs is a singleton ancor object exporting SubsPersistenceInterface.

type TopicsPersistenceInterface

type TopicsPersistenceInterface interface {
	Create(topic *types.Topic, owner types.Uid, private interface{}) error
	CreateP2P(initiator, invited *types.Subscription) error
	Get(topic string) (*types.Topic, error)
	GetUsers(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	GetUsersAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	GetSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	GetSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	Update(topic string, update map[string]interface{}) error
	OwnerChange(topic string, newOwner types.Uid) error
	Delete(topic string, isChan, hard bool) error
}

TopicsPersistenceInterface is an interface which defines methods for persistent storage of topics.

Topics is a singleton ancor object exporting TopicsPersistenceInterface methods.

type UsersPersistenceInterface

type UsersPersistenceInterface interface {
	Create(user *types.User, private interface{}) (*types.User, error)
	GetAuthRecord(user types.Uid, scheme string) (string, auth.Level, []byte, time.Time, error)
	GetAuthUniqueRecord(scheme, unique string) (types.Uid, auth.Level, []byte, time.Time, error)
	AddAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) error
	UpdateAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) error
	DelAuthRecords(uid types.Uid, scheme string) error
	Get(uid types.Uid) (*types.User, error)
	GetAll(uid ...types.Uid) ([]types.User, error)
	GetByCred(method, value string) (types.Uid, error)
	Delete(id types.Uid, hard bool) error
	UpdateLastSeen(uid types.Uid, userAgent string, when time.Time) error
	Update(uid types.Uid, update map[string]interface{}) error
	UpdateTags(uid types.Uid, add, remove, reset []string) ([]string, error)
	UpdateState(uid types.Uid, state types.ObjState) error
	GetSubs(id types.Uid) ([]types.Subscription, error)
	FindSubs(id types.Uid, required [][]string, optional []string) ([]types.Subscription, error)
	GetTopics(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
	GetTopicsAny(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
	GetOwnTopics(id types.Uid) ([]string, error)
	GetChannels(id types.Uid) ([]string, error)
	UpsertCred(cred *types.Credential) (bool, error)
	ConfirmCred(id types.Uid, method string) error
	FailCred(id types.Uid, method string) error
	GetActiveCred(id types.Uid, method string) (*types.Credential, error)
	GetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)
	DelCred(id types.Uid, method, value string) error
	GetUnreadCount(ids ...types.Uid) (map[types.Uid]int, error)
}

UsersPersistenceInterface is an interface which defines methods for persistent storage of user records.

Users is a singleton ancor object exporting UsersPersistenceInterface methods.

Directories

Path Synopsis
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.
Package types provides data types for persisting objects in the databases.
Package types provides data types for persisting objects in the databases.

Jump to

Keyboard shortcuts

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