database

package
v0.0.0-...-d26b62e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const Offline = 0
View Source
const Online = 1

Variables

This section is empty.

Functions

func IsDup

func IsDup(err error) bool

IsDup returns whether err informs of a duplicate key error because a primary key index or a secondary unique index already has an entry with the given value.

Types

type MongoUserDB

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

func NewUserDatabase

func NewUserDatabase(logger *zap.SugaredLogger, userCache *cache.Cache) *MongoUserDB

func (*MongoUserDB) CreateUser

func (db *MongoUserDB) CreateUser(user *models.User) error

func (*MongoUserDB) DeleteUser

func (db *MongoUserDB) DeleteUser(user *models.User) error

func (*MongoUserDB) FindByEmail

func (db *MongoUserDB) FindByEmail(email string) (*models.User, error)

FindByEmail returns the user, if found, with the given email. This is NOT cached

func (*MongoUserDB) FindById

func (db *MongoUserDB) FindById(id string) (*models.User, error)

FindById returns the user, if found, with the given id. This is cached

func (*MongoUserDB) FindByUsername

func (db *MongoUserDB) FindByUsername(username string) (*models.User, error)

FindByUsername returns the user, if found, with the given username. This is NOT cached

func (*MongoUserDB) GetCache

func (db *MongoUserDB) GetCache(id string) (*models.User, bool, error)

func (*MongoUserDB) SetCache

func (db *MongoUserDB) SetCache(user *models.User) error

func (*MongoUserDB) UpdateUser

func (db *MongoUserDB) UpdateUser(user *models.User) error

type OnlineStatus

type OnlineStatus struct {
	Status byte   `json:"status"`
	GameId string `json:"gameId"`
}

type OnlineStatusDB

type OnlineStatusDB interface {
	//SetOnlineStatus sets the online status of the user
	SetOnlineStatus(id string, status *OnlineStatus) error

	//GetOnlineStatus returns the online status of the user
	GetOnlineStatus(id string) (*OnlineStatus, error)
}

type RedisStatusDatabase

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

func NewOnlineStatusDatabase

func NewOnlineStatusDatabase(logger *zap.SugaredLogger, client *redis.Client) *RedisStatusDatabase

func (*RedisStatusDatabase) GetOnlineStatus

func (db *RedisStatusDatabase) GetOnlineStatus(id string) (*OnlineStatus, error)

func (*RedisStatusDatabase) SetOnlineStatus

func (db *RedisStatusDatabase) SetOnlineStatus(id string, status *OnlineStatus) error

type UserDB

type UserDB interface {
	//CreateUser saves the new user to the database. If a user with the same id exists already, a error will be returned.
	CreateUser(user *models.User) error
	//UpdateUser updates the existing user.
	UpdateUser(user *models.User) error
	//DeleteUser deletes the user from the database.
	DeleteUser(user *models.User) error
	//FindById returns the user, if found, with the given id. This is Cached
	FindById(id string) (*models.User, error)
	//FindByEmail returns the user, if found, with the given email. This is NOT Cached
	FindByEmail(email string) (*models.User, error)
	//FindByUsername returns the user, if found, with the given username. This is NOT Cached
	FindByUsername(username string) (*models.User, error)
}

UserDB is the interface for the user database.

Jump to

Keyboard shortcuts

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