memory

package
v0.4.19 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package memory implements the database interface using in-memory database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is an in-memory database for testing or temporarily.

func New

func New() (*DB, error)

New returns a new in-memory database.

func (*DB) ActivateClient

func (d *DB) ActivateClient(
	_ context.Context,
	projectID types.ID,
	key string,
) (*database.ClientInfo, error)

ActivateClient activates a client.

func (*DB) Close

func (d *DB) Close() error

Close closes the database.

func (*DB) CreateChangeInfos

func (d *DB) CreateChangeInfos(
	_ context.Context,
	projectID types.ID,
	docInfo *database.DocInfo,
	initialServerSeq int64,
	changes []*change.Change,
	isRemoved bool,
) error

CreateChangeInfos stores the given changes and doc info. If the removeDoc condition is true, mark IsRemoved to true in doc info.

func (*DB) CreateProjectInfo

func (d *DB) CreateProjectInfo(
	_ context.Context,
	name string,
	owner types.ID,
	clientDeactivateThreshold string,
) (*database.ProjectInfo, error)

CreateProjectInfo creates a new project.

func (*DB) CreateSnapshotInfo

func (d *DB) CreateSnapshotInfo(
	_ context.Context,
	docRefKey types.DocRefKey,
	doc *document.InternalDocument,
) error

CreateSnapshotInfo stores the snapshot of the given document.

func (*DB) CreateUserInfo added in v0.2.14

func (d *DB) CreateUserInfo(
	_ context.Context,
	username string,
	hashedPassword string,
) (*database.UserInfo, error)

CreateUserInfo creates a new user.

func (*DB) DeactivateClient

func (d *DB) DeactivateClient(_ context.Context, refKey types.ClientRefKey) (*database.ClientInfo, error)

DeactivateClient deactivates a client.

func (*DB) EnsureDefaultUserAndProject added in v0.2.14

func (d *DB) EnsureDefaultUserAndProject(
	ctx context.Context,
	username,
	password string,
	clientDeactivateThreshold string,
) (*database.UserInfo, *database.ProjectInfo, error)

EnsureDefaultUserAndProject creates the default user and project if they do not exist.

func (*DB) FindChangeInfosBetweenServerSeqs

func (d *DB) FindChangeInfosBetweenServerSeqs(
	_ context.Context,
	docRefKey types.DocRefKey,
	from int64,
	to int64,
) ([]*database.ChangeInfo, error)

FindChangeInfosBetweenServerSeqs returns the changeInfos between two server sequences.

func (*DB) FindChangesBetweenServerSeqs

func (d *DB) FindChangesBetweenServerSeqs(
	ctx context.Context,
	docRefKey types.DocRefKey,
	from int64,
	to int64,
) ([]*change.Change, error)

FindChangesBetweenServerSeqs returns the changes between two server sequences.

func (*DB) FindClientInfoByRefKey added in v0.4.14

func (d *DB) FindClientInfoByRefKey(_ context.Context, refKey types.ClientRefKey) (*database.ClientInfo, error)

FindClientInfoByRefKey finds a client by the given refKey.

func (*DB) FindClosestSnapshotInfo

func (d *DB) FindClosestSnapshotInfo(
	_ context.Context,
	docRefKey types.DocRefKey,
	serverSeq int64,
	includeSnapshot bool,
) (*database.SnapshotInfo, error)

FindClosestSnapshotInfo finds the last snapshot of the given document.

func (*DB) FindDeactivateCandidatesPerProject added in v0.4.13

func (d *DB) FindDeactivateCandidatesPerProject(
	_ context.Context,
	project *database.ProjectInfo,
	candidatesLimit int,
) ([]*database.ClientInfo, error)

FindDeactivateCandidatesPerProject finds the clients that need housekeeping per project.

func (*DB) FindDocInfoByKey

func (d *DB) FindDocInfoByKey(
	_ context.Context,
	projectID types.ID,
	key key.Key,
) (*database.DocInfo, error)

FindDocInfoByKey finds the document of the given key.

func (*DB) FindDocInfoByKeyAndOwner added in v0.2.9

func (d *DB) FindDocInfoByKeyAndOwner(
	_ context.Context,
	clientRefKey types.ClientRefKey,
	key key.Key,
	createDocIfNotExist bool,
) (*database.DocInfo, error)

FindDocInfoByKeyAndOwner finds the document of the given key. If the createDocIfNotExist condition is true, create the document if it does not exist.

func (*DB) FindDocInfoByRefKey added in v0.4.14

func (d *DB) FindDocInfoByRefKey(
	_ context.Context,
	refKey types.DocRefKey,
) (*database.DocInfo, error)

FindDocInfoByRefKey finds a docInfo of the given refKey.

func (*DB) FindDocInfosByPaging

func (d *DB) FindDocInfosByPaging(
	_ context.Context,
	projectID types.ID,
	paging types.Paging[types.ID],
) ([]*database.DocInfo, error)

FindDocInfosByPaging returns the documentInfos of the given paging.

func (*DB) FindDocInfosByQuery added in v0.2.13

func (d *DB) FindDocInfosByQuery(
	_ context.Context,
	projectID types.ID,
	query string,
	pageSize int,
) (*types.SearchResult[*database.DocInfo], error)

FindDocInfosByQuery returns the docInfos which match the given query.

func (*DB) FindMinSyncedSeqInfo added in v0.2.17

func (d *DB) FindMinSyncedSeqInfo(
	_ context.Context,
	docRefKey types.DocRefKey,
) (*database.SyncedSeqInfo, error)

FindMinSyncedSeqInfo finds the minimum synced sequence info.

func (*DB) FindNextNCyclingProjectInfos added in v0.4.13

func (d *DB) FindNextNCyclingProjectInfos(
	_ context.Context,
	pageSize int,
	lastProjectID types.ID,
) ([]*database.ProjectInfo, error)

FindNextNCyclingProjectInfos finds the next N cycling projects from the given projectID.

func (*DB) FindProjectInfoByID added in v0.2.8

func (d *DB) FindProjectInfoByID(_ context.Context, id types.ID) (*database.ProjectInfo, error)

FindProjectInfoByID returns a project by the given id.

func (*DB) FindProjectInfoByName added in v0.2.6

func (d *DB) FindProjectInfoByName(
	_ context.Context,
	owner types.ID,
	name string,
) (*database.ProjectInfo, error)

FindProjectInfoByName returns a project by the given name.

func (*DB) FindProjectInfoByPublicKey

func (d *DB) FindProjectInfoByPublicKey(
	_ context.Context,
	publicKey string,
) (*database.ProjectInfo, error)

FindProjectInfoByPublicKey returns a project by public key.

func (*DB) FindProjectInfoBySecretKey added in v0.4.13

func (d *DB) FindProjectInfoBySecretKey(
	_ context.Context,
	secretKey string,
) (*database.ProjectInfo, error)

FindProjectInfoBySecretKey returns a project by secret key.

func (*DB) FindSnapshotInfoByRefKey added in v0.4.14

func (d *DB) FindSnapshotInfoByRefKey(
	_ context.Context,
	refKey types.SnapshotRefKey,
) (*database.SnapshotInfo, error)

FindSnapshotInfoByRefKey returns the snapshot by the given refKey.

func (*DB) FindUserInfoByID added in v0.4.13

func (d *DB) FindUserInfoByID(_ context.Context, clientID types.ID) (*database.UserInfo, error)

FindUserInfoByID finds a user by the given ID.

func (*DB) FindUserInfoByName added in v0.4.14

func (d *DB) FindUserInfoByName(_ context.Context, username string) (*database.UserInfo, error)

FindUserInfoByName finds a user by the given username.

func (*DB) IsDocumentAttached added in v0.4.3

func (d *DB) IsDocumentAttached(
	_ context.Context,
	refKey types.DocRefKey,
	excludeClientID types.ID,
) (bool, error)

IsDocumentAttached returns whether the document is attached to clients.

func (*DB) ListProjectInfos

func (d *DB) ListProjectInfos(
	_ context.Context,
	owner types.ID,
) ([]*database.ProjectInfo, error)

ListProjectInfos returns all project infos owned by owner.

func (*DB) ListUserInfos added in v0.2.14

func (d *DB) ListUserInfos(_ context.Context) ([]*database.UserInfo, error)

ListUserInfos returns all users.

func (*DB) PurgeStaleChanges added in v0.2.17

func (d *DB) PurgeStaleChanges(
	_ context.Context,
	docRefKey types.DocRefKey,
) error

PurgeStaleChanges delete changes before the smallest in `syncedseqs` to save storage.

func (*DB) UpdateAndFindMinSyncedTicket

func (d *DB) UpdateAndFindMinSyncedTicket(
	ctx context.Context,
	clientInfo *database.ClientInfo,
	docRefKey types.DocRefKey,
	serverSeq int64,
) (*time.Ticket, error)

UpdateAndFindMinSyncedTicket updates the given serverSeq of the given client and returns the min synced ticket.

func (*DB) UpdateClientInfoAfterPushPull

func (d *DB) UpdateClientInfoAfterPushPull(
	_ context.Context,
	clientInfo *database.ClientInfo,
	docInfo *database.DocInfo,
) error

UpdateClientInfoAfterPushPull updates the client from the given clientInfo after handling PushPull.

func (*DB) UpdateDocInfoStatusToRemoved added in v0.4.0

func (d *DB) UpdateDocInfoStatusToRemoved(
	_ context.Context,
	refKey types.DocRefKey,
) error

UpdateDocInfoStatusToRemoved updates the status of the document to removed.

func (*DB) UpdateProjectInfo

func (d *DB) UpdateProjectInfo(
	_ context.Context,
	owner types.ID,
	id types.ID,
	fields *types.UpdatableProjectFields,
) (*database.ProjectInfo, error)

UpdateProjectInfo updates the given project.

func (*DB) UpdateSyncedSeq

func (d *DB) UpdateSyncedSeq(
	_ context.Context,
	clientInfo *database.ClientInfo,
	docRefKey types.DocRefKey,
	serverSeq int64,
) error

UpdateSyncedSeq updates the syncedSeq of the given client.

Jump to

Keyboard shortcuts

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