db

package
v0.0.0-...-c857007 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package db interacts with storing user attributes so they can be retrieved after the server restarts

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	// contains filtered or unexported methods
}

Database contains methods to create, read, update, and delete data

func NewPostgresDatabase

func NewPostgresDatabase(databaseURL string) (Database, error)

NewPostgresDatabase creates a postgres database from a databaseURL

type User

type User struct {
	Username username

	Points int
	// contains filtered or unexported fields
}

User contains information for each player

func NewUser

func NewUser(u, p string) (*User, error)

NewUser creates a new user with the specified name and password.

type UserDao

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

UserDao contains CRUD operations for user-related information

func (UserDao) Create

func (ud UserDao) Create(ctx context.Context, u User) error

Create adds a user

func (UserDao) Delete

func (ud UserDao) Delete(ctx context.Context, u User) error

Delete removes a user

func (UserDao) Read

func (ud UserDao) Read(ctx context.Context, u User) (User, error)

Read gets information such as points

func (UserDao) Setup

func (ud UserDao) Setup(ctx context.Context) error

Setup initializes the tables and adds the functions

func (UserDao) UpdatePassword

func (ud UserDao) UpdatePassword(ctx context.Context, u User, newP string) error

UpdatePassword sets the password of a user

func (UserDao) UpdatePointsIncrement

func (ud UserDao) UpdatePointsIncrement(ctx context.Context, usernames []string, f UserPointsIncrementFunc) error

UpdatePointsIncrement increments the points for multiple users

type UserDaoConfig

type UserDaoConfig struct {
	// Debug is a flag that causes the socket to log the types non-ping/pong messages that are read/written
	DB Database
	// QueryPeriod is the amount of time that any database action can take before it should timeout
	QueryPeriod time.Duration
}

UserDaoConfig contains commonly shared UserDao properties

func (UserDaoConfig) NewUserDao

func (cfg UserDaoConfig) NewUserDao() (*UserDao, error)

NewUserDao creates a UserDao on the specified database

type UserPointsIncrementFunc

type UserPointsIncrementFunc func(username string) int

UserPointsIncrementFunc is used to determine how much to increment the points for a username

Jump to

Keyboard shortcuts

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