mongo

package
v0.4.18 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package mongo implements database interfaces using MongoDB.

Index

Constants

View Source
const (
	// ColProjects represents the projects collection in the database.
	ColProjects = "projects"
	// ColUsers represents the users collection in the database.
	ColUsers = "users"
	// ColClients represents the clients collection in the database.
	ColClients = "clients"
	// ColDocuments represents the documents collection in the database.
	ColDocuments = "documents"
	// ColChanges represents the changes collection in the database.
	ColChanges = "changes"
	// ColSnapshots represents the snapshots collection in the database.
	ColSnapshots = "snapshots"
	// ColSyncedSeqs represents the syncedseqs collection in the database.
	ColSyncedSeqs = "syncedseqs"
)
View Source
const (
	// StatusKey is the key of the status field.
	StatusKey = "status"
)

Variables

Collections represents the list of all collections in the database.

Functions

func NewRegistryBuilder added in v0.4.14

func NewRegistryBuilder() *bsoncodec.RegistryBuilder

NewRegistryBuilder returns a new registry builder with the default encoder and decoder.

Types

type Client

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

Client is a client that connects to Mongo DB and reads or saves Yorkie data.

func Dial

func Dial(conf *Config) (*Client, error)

Dial creates an instance of Client and dials the given MongoDB.

func (*Client) ActivateClient

func (c *Client) ActivateClient(ctx context.Context, projectID types.ID, key string) (*database.ClientInfo, error)

ActivateClient activates the client of the given key.

func (*Client) Close

func (c *Client) Close() error

Close all resources of this client.

func (*Client) CreateChangeInfos

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

CreateChangeInfos stores the given changes and doc info.

func (*Client) CreateProjectInfo

func (c *Client) CreateProjectInfo(
	ctx context.Context,
	name string,
	owner types.ID,
	clientDeactivateThreshold string,
) (*database.ProjectInfo, error)

CreateProjectInfo creates a new project.

func (*Client) CreateSnapshotInfo

func (c *Client) CreateSnapshotInfo(
	ctx context.Context,
	docRefKey types.DocRefKey,
	doc *document.InternalDocument,
) error

CreateSnapshotInfo stores the snapshot of the given document.

func (*Client) CreateUserInfo added in v0.2.14

func (c *Client) CreateUserInfo(
	ctx context.Context,
	username string,
	hashedPassword string,
) (*database.UserInfo, error)

CreateUserInfo creates a new user.

func (*Client) DeactivateClient

func (c *Client) DeactivateClient(ctx context.Context, refKey types.ClientRefKey) (*database.ClientInfo, error)

DeactivateClient deactivates the client of the given refKey.

func (*Client) EnsureDefaultUserAndProject added in v0.2.14

func (c *Client) 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 (*Client) FindChangeInfosBetweenServerSeqs

func (c *Client) FindChangeInfosBetweenServerSeqs(
	ctx context.Context,
	docRefKey types.DocRefKey,
	from int64,
	to int64,
) ([]*database.ChangeInfo, error)

FindChangeInfosBetweenServerSeqs returns the changeInfos between two server sequences.

func (*Client) FindChangesBetweenServerSeqs

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

FindChangesBetweenServerSeqs returns the changes between two server sequences.

func (*Client) FindClientInfoByRefKey added in v0.4.14

func (c *Client) FindClientInfoByRefKey(ctx context.Context, refKey types.ClientRefKey) (*database.ClientInfo, error)

FindClientInfoByRefKey finds the client of the given refKey.

func (*Client) FindClosestSnapshotInfo

func (c *Client) FindClosestSnapshotInfo(
	ctx context.Context,
	docRefKey types.DocRefKey,
	serverSeq int64,
	includeSnapshot bool,
) (*database.SnapshotInfo, error)

FindClosestSnapshotInfo finds the last snapshot of the given document.

func (*Client) FindDeactivateCandidatesPerProject added in v0.4.13

func (c *Client) FindDeactivateCandidatesPerProject(
	ctx context.Context,
	project *database.ProjectInfo,
	candidatesLimit int,
) ([]*database.ClientInfo, error)

FindDeactivateCandidatesPerProject finds the clients that need housekeeping per project.

func (*Client) FindDocInfoByKey

func (c *Client) FindDocInfoByKey(
	ctx context.Context,
	projectID types.ID,
	docKey key.Key,
) (*database.DocInfo, error)

FindDocInfoByKey finds the document of the given key.

func (*Client) FindDocInfoByKeyAndOwner added in v0.2.9

func (c *Client) FindDocInfoByKeyAndOwner(
	ctx context.Context,
	clientRefKey types.ClientRefKey,
	docKey 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 (*Client) FindDocInfoByRefKey added in v0.4.14

func (c *Client) FindDocInfoByRefKey(
	ctx context.Context,
	refKey types.DocRefKey,
) (*database.DocInfo, error)

FindDocInfoByRefKey finds a docInfo of the given refKey.

func (*Client) FindDocInfosByPaging

func (c *Client) FindDocInfosByPaging(
	ctx context.Context,
	projectID types.ID,
	paging types.Paging[types.ID],
) ([]*database.DocInfo, error)

FindDocInfosByPaging returns the docInfos of the given paging.

func (*Client) FindDocInfosByQuery added in v0.2.13

func (c *Client) FindDocInfosByQuery(
	ctx context.Context,
	projectID types.ID,
	query string,
	pageSize int,
) (*types.SearchResult[*database.DocInfo], error)

FindDocInfosByQuery returns the docInfos which match the given query.

func (*Client) FindMinSyncedSeqInfo added in v0.2.17

func (c *Client) FindMinSyncedSeqInfo(
	ctx context.Context,
	docRefKey types.DocRefKey,
) (*database.SyncedSeqInfo, error)

FindMinSyncedSeqInfo finds the minimum synced sequence info.

func (*Client) FindNextNCyclingProjectInfos added in v0.4.13

func (c *Client) FindNextNCyclingProjectInfos(
	ctx context.Context,
	pageSize int,
	lastProjectID types.ID,
) ([]*database.ProjectInfo, error)

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

func (*Client) FindProjectInfoByID added in v0.2.8

func (c *Client) FindProjectInfoByID(ctx context.Context, id types.ID) (*database.ProjectInfo, error)

FindProjectInfoByID returns a project by the given id.

func (*Client) FindProjectInfoByName added in v0.2.6

func (c *Client) FindProjectInfoByName(
	ctx context.Context,
	owner types.ID,
	name string,
) (*database.ProjectInfo, error)

FindProjectInfoByName returns a project by name.

func (*Client) FindProjectInfoByPublicKey

func (c *Client) FindProjectInfoByPublicKey(ctx context.Context, publicKey string) (*database.ProjectInfo, error)

FindProjectInfoByPublicKey returns a project by public key.

func (*Client) FindProjectInfoBySecretKey added in v0.4.13

func (c *Client) FindProjectInfoBySecretKey(ctx context.Context, secretKey string) (*database.ProjectInfo, error)

FindProjectInfoBySecretKey returns a project by secret key.

func (*Client) FindSnapshotInfoByRefKey added in v0.4.14

func (c *Client) FindSnapshotInfoByRefKey(
	ctx context.Context,
	refKey types.SnapshotRefKey,
) (*database.SnapshotInfo, error)

FindSnapshotInfoByRefKey returns the snapshot by the given refKey.

func (*Client) FindUserInfoByID added in v0.4.13

func (c *Client) FindUserInfoByID(ctx context.Context, clientID types.ID) (*database.UserInfo, error)

FindUserInfoByID returns a user by ID.

func (*Client) FindUserInfoByName added in v0.4.14

func (c *Client) FindUserInfoByName(ctx context.Context, username string) (*database.UserInfo, error)

FindUserInfoByName returns a user by username.

func (*Client) IsDocumentAttached added in v0.4.3

func (c *Client) IsDocumentAttached(
	ctx context.Context,
	docRefKey types.DocRefKey,
	excludeClientID types.ID,
) (bool, error)

IsDocumentAttached returns whether the given document is attached to clients.

func (*Client) ListProjectInfos

func (c *Client) ListProjectInfos(
	ctx context.Context,
	owner types.ID,
) ([]*database.ProjectInfo, error)

ListProjectInfos returns all project infos owned by owner.

func (*Client) ListUserInfos added in v0.2.14

func (c *Client) ListUserInfos(
	ctx context.Context,
) ([]*database.UserInfo, error)

ListUserInfos returns all users.

func (*Client) PurgeStaleChanges added in v0.2.17

func (c *Client) PurgeStaleChanges(
	ctx context.Context,
	docRefKey types.DocRefKey,
) error

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

func (*Client) UpdateAndFindMinSyncedTicket

func (c *Client) 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 (*Client) UpdateClientInfoAfterPushPull

func (c *Client) UpdateClientInfoAfterPushPull(
	ctx context.Context,
	clientInfo *database.ClientInfo,
	docInfo *database.DocInfo,
) error

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

func (*Client) UpdateDocInfoStatusToRemoved added in v0.4.0

func (c *Client) UpdateDocInfoStatusToRemoved(
	ctx context.Context,
	refKey types.DocRefKey,
) error

UpdateDocInfoStatusToRemoved updates the document status to removed.

func (*Client) UpdateProjectInfo

func (c *Client) UpdateProjectInfo(
	ctx context.Context,
	owner types.ID,
	id types.ID,
	fields *types.UpdatableProjectFields,
) (*database.ProjectInfo, error)

UpdateProjectInfo updates the project info.

func (*Client) UpdateSyncedSeq

func (c *Client) UpdateSyncedSeq(
	ctx context.Context,
	clientInfo *database.ClientInfo,
	docRefKey types.DocRefKey,
	serverSeq int64,
) error

UpdateSyncedSeq updates the syncedSeq of the given client.

type Config

type Config struct {
	ConnectionTimeout string `yaml:"ConnectionTimeout"`
	ConnectionURI     string `yaml:"ConnectionURI"`
	YorkieDatabase    string `yaml:"YorkieDatabase"`
	PingTimeout       string `yaml:"PingTimeout"`
}

Config is the configuration for creating a Client instance.

func (*Config) ParseConnectionTimeout

func (c *Config) ParseConnectionTimeout() time.Duration

ParseConnectionTimeout returns connection timeout duration.

func (*Config) ParsePingTimeout

func (c *Config) ParsePingTimeout() time.Duration

ParsePingTimeout returns ping timeout duration.

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the provided Config is invalidated.

Jump to

Keyboard shortcuts

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