db

package
v0.0.0-...-0de1ee4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableBattle            = "battle"
	IndexBattleId          = "id"
	IndexBattleAggregateId = "aggregateId"
	IndexBattlePlayerId    = "playerId"
)
View Source
const (
	IndexMatchId        = "id"
	IndexMatchPlayerId  = "playerId"
	IndexMatchIsWaiting = "isWaiting"
)
View Source
const (
	TableMatch = "match"
)

Variables

View Source
var BattleTableSchema = &memdb.TableSchema{
	Name: TableBattle,
	Indexes: map[string]*memdb.IndexSchema{
		IndexBattleId: {
			Name:   IndexBattleId,
			Unique: true,
			Indexer: &memdb.StringFieldIndex{
				Field: "Id",
			},
		},
		IndexBattleAggregateId: {
			Name:    IndexBattleAggregateId,
			Unique:  true,
			Indexer: &BattleVersionIndexer{},
		},
	},
}
View Source
var DefaultSet = wire.NewSet(
	NewDatabase,
)
View Source
var MatchTableSchema = &memdb.TableSchema{
	Name: TableMatch,
	Indexes: map[string]*memdb.IndexSchema{
		IndexMatchId: {
			Name:   IndexMatchId,
			Unique: true,
			Indexer: &memdb.StringFieldIndex{
				Field: "Id",
			},
		},
		IndexMatchPlayerId: {
			Name:    IndexMatchPlayerId,
			Unique:  false,
			Indexer: &MatchPlayerIdIndexer{},
		},
		IndexMatchIsWaiting: {
			Name:   IndexMatchIsWaiting,
			Unique: false,
			Indexer: &memdb.ConditionalIndex{
				Conditional: MatchWaitingIndexFunc,
			},
		},
	},
}

Functions

func MatchWaitingIndexFunc

func MatchWaitingIndexFunc(obj any) (bool, error)

Types

type BattleEvent

type BattleEvent struct {
	Id          string
	AggregateId string
	Type        string
	Version     int
	CreatedAt   int64
}

type BattleVersionIndexer

type BattleVersionIndexer struct{}

func (*BattleVersionIndexer) FromArgs

func (i *BattleVersionIndexer) FromArgs(args ...any) ([]byte, error)

func (*BattleVersionIndexer) FromObject

func (i *BattleVersionIndexer) FromObject(obj any) (bool, [][]byte, error)

type Database

type Database struct {
	*memdb.MemDB
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase() (*Database, error)

func (*Database) Txn

func (d *Database) Txn(write bool) *memdb.Txn

func (*Database) Watch

func (d *Database) Watch() *Watcher

type Match

type Match struct {
	Id      string
	Players []MatchPlayer
}

type MatchPlayer

type MatchPlayer struct {
	Id   string
	Team int
}

type MatchPlayerIdIndexer

type MatchPlayerIdIndexer struct{}

func (*MatchPlayerIdIndexer) FromArgs

func (i *MatchPlayerIdIndexer) FromArgs(args ...interface{}) ([]byte, error)

func (*MatchPlayerIdIndexer) FromObject

func (i *MatchPlayerIdIndexer) FromObject(obj any) (bool, [][]byte, error)

type Subscriber

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

func NewSubscriber

func NewSubscriber(watcher *Watcher) *Subscriber

func (*Subscriber) Close

func (s *Subscriber) Close() error

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)

type Watcher

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

func NewWatcher

func NewWatcher() *Watcher

func (*Watcher) Close

func (w *Watcher) Close()

func (*Watcher) Closed

func (w *Watcher) Closed() bool

Jump to

Keyboard shortcuts

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