common

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTxOptions = pgx.TxOptions{
	IsoLevel:       pgx.ReadCommitted,
	AccessMode:     pgx.ReadWrite,
	DeferrableMode: pgx.Deferrable,
}
View Source
var GormLogger logger.Interface
View Source
var InitialRating = &entity.SingleRating{
	Rating:          float64(glicko.InitialRating),
	RatingDeviation: float64(glicko.InitialRatingDeviation),
	Volatility:      glicko.InitialVolatility,
}
View Source
var MigrationsPath = os.Getenv("DB_MIGRATIONS_PATH")
View Source
var RepeatableReadTxOptions = pgx.TxOptions{
	IsoLevel:       pgx.RepeatableRead,
	AccessMode:     pgx.ReadWrite,
	DeferrableMode: pgx.Deferrable,
}
View Source
var SelectByTypeToString = map[SelectByType]string{
	SelectByUUID:           "uuid",
	SelectByID:             "id",
	SelectByUserID:         "user_id",
	SelectByUsername:       "lower(username)",
	SelectByEmail:          "lower(email)",
	SelectByAPIKey:         "api_key",
	SelectBySeekerID:       "seeker",
	SelectBySeekerConnID:   "seeker_conn_id",
	SelectByReceiverID:     "receiver",
	SelectByReceiverConnID: "receiver_conn_id",
}
View Source
var TableTypeToString = map[TableType]string{
	UsersTable:       "users",
	ProfilesTable:    "profiles",
	GamesTable:       "games",
	PuzzlesTable:     "puzzles",
	SoughtGamesTable: "soughtgames",
}
View Source
var TestDBHost = os.Getenv("TEST_DB_HOST")
View Source
var TestDBPassword = os.Getenv("DB_PASSWORD")
View Source
var TestDBPort = os.Getenv("DB_PORT")
View Source
var TestDBPrefix = os.Getenv("TEST_DB_PREFIX")
View Source
var TestDBSSLMode = os.Getenv("DB_SSL_MODE")
View Source
var TestDBUser = os.Getenv("DB_USER")

Functions

func BuildIn

func BuildIn(num int, start int) string

func Delete

func Delete(ctx context.Context, tx pgx.Tx, cfg *CommonDBConfig) error

func GetDBIDFromUUID

func GetDBIDFromUUID(ctx context.Context, pool *pgxpool.Pool, cfg *CommonDBConfig) (int64, error)

func GetGameDBIDFromUUID

func GetGameDBIDFromUUID(ctx context.Context, tx pgx.Tx, uuid string) (int64, error)

func GetGameInfo

func GetGameInfo(ctx context.Context, tx pgx.Tx, gameId int) (*macondopb.GameHistory, *ipc.GameRequest, string, error)

func GetPuzzleDBIDFromUUID

func GetPuzzleDBIDFromUUID(ctx context.Context, tx pgx.Tx, uuid string) (int64, error)

func GetUserBy

func GetUserBy(ctx context.Context, tx pgx.Tx, cfg *CommonDBConfig) (*entity.User, error)

func GetUserDBIDFromUUID

func GetUserDBIDFromUUID(ctx context.Context, tx pgx.Tx, uuid string) (int64, error)

func GetUserRating

func GetUserRating(ctx context.Context, tx pgx.Tx, userId int64, ratingKey entity.VariantKey) (*entity.SingleRating, error)

func GetUserRatingWithPool

func GetUserRatingWithPool(ctx context.Context, pool *pgxpool.Pool, userId int64, ratingKey entity.VariantKey) (*entity.SingleRating, error)

func GetUserStats

func GetUserStats(ctx context.Context, tx pgx.Tx, userId int64, ratingKey entity.VariantKey) (*entity.Stats, error)

func GetUserStatsWithPool

func GetUserStatsWithPool(ctx context.Context, pool *pgxpool.Pool, userId int64, ratingKey entity.VariantKey) (*entity.Stats, error)

func GetUserUUIDFromDBID

func GetUserUUIDFromDBID(ctx context.Context, tx pgx.Tx, DBID int64) (string, error)

func GetUsernameFromUUID

func GetUsernameFromUUID(ctx context.Context, tx pgx.Tx, uuid string) (string, error)

func InitializeUserRating

func InitializeUserRating(ctx context.Context, tx pgx.Tx, userId int64) error

func InitializeUserStats

func InitializeUserStats(ctx context.Context, tx pgx.Tx, userId int64) error

func OpenDB

func OpenDB(host, port, name, user, password, sslmode string) (*pgxpool.Pool, error)

func OpenTestingDB

func OpenTestingDB(pkg string) (*pgxpool.Pool, error)

func PostgresConnDSN

func PostgresConnDSN(host, port, name, user, password, sslmode string) string

PostgresConnDSN is obsolete and only for Gorm. Remove once we get rid of gorm.

func PostgresConnUri

func PostgresConnUri(host, port, name, user, password, sslmode string) string

func RecreateTestDB

func RecreateTestDB(pkg string) error

func TeardownTestDB

func TeardownTestDB(pkg string) error

func TestDBName

func TestDBName(pkg string) string

func TestingPostgresConnDSN

func TestingPostgresConnDSN(pkg string) string

XXX: Delete me after removing Gorm

func TestingPostgresConnUri

func TestingPostgresConnUri(pkg string) string

func Update

func Update(ctx context.Context, tx pgx.Tx, columns []string, args []interface{}, cfg *CommonDBConfig) error

func UpdateUserRating

func UpdateUserRating(ctx context.Context, tx pgx.Tx, userId int64, ratingKey entity.VariantKey, newRating *entity.SingleRating) error

func UpdateUserStats

func UpdateUserStats(ctx context.Context, tx pgx.Tx, userId int64, ratingKey entity.VariantKey, newStats *entity.Stats) error

func UpdateWithPool

func UpdateWithPool(ctx context.Context, pool *pgxpool.Pool, columns []string, args []interface{}, cfg *CommonDBConfig) error

Types

type CommonDBConfig

type CommonDBConfig struct {
	SelectByType     SelectByType
	TableType        TableType
	RowsAffectedType RowsAffectedType
	Value            interface{}
	SetUpdatedAt     bool
	IncludeProfile   bool
}

type RowIterator

type RowIterator interface {
	Close()
	Next() bool
	Scan(dest ...interface{}) error
}

type RowsAffectedType

type RowsAffectedType int
const (
	AnyRowsAffected RowsAffectedType = iota
	AtMostOneRowAffected
	ExactlyOneRowAffected
	AtLeastOneRowAffected
)

type SelectByType

type SelectByType int
const (
	SelectByUUID SelectByType = iota
	SelectByID
	SelectByUserID
	SelectByUsername
	SelectByEmail
	SelectByAPIKey
	SelectBySeekerID
	SelectBySeekerConnID
	SelectByReceiverID
	SelectByReceiverConnID
)

type TableType

type TableType int
const (
	UsersTable TableType = iota
	ProfilesTable
	GamesTable
	PuzzlesTable
	SoughtGamesTable
)

Jump to

Keyboard shortcuts

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