db

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package db handles interactions with the MongoDB instance and works as an abstraction layer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PGTimestamp added in v0.0.2

func PGTimestamp(t time.Time) pgtype.Timestamp

PGTimestamp converts a `time.Time` to a `pgx`-compatible `pgtype.Timestamp`.

func PGUint64 added in v0.0.2

func PGUint64(x uint64) pgtype.Numeric

PGUint64 converts a `uint64` to a `pgx`-compatible `pgtype.Numeric`.

Types

type Assignment added in v0.0.2

type Assignment struct {
	gen.Assignment
	Tasks []gen.AssignmentTask
}

Assignment implements EntityMerger

func (*Assignment) Merge added in v0.0.2

func (a *Assignment) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger.

type Campaign added in v0.0.2

type Campaign gen.Campaign

Campaign implements EntityMerger

func (*Campaign) Merge added in v0.0.2

func (c *Campaign) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger. It is assumed that the currently known planets are already present in the database.

type Client

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

Client is the abstraction layer for the MongoDB connector

func New

func New(cfg *config.Config, logger *log.Logger) (*Client, error)

New creates a new client and connects it to the DB

func (*Client) Connect added in v0.0.3

func (c *Client) Connect(ctx context.Context) error

Connect implements main.ConnectWaiter.

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect disconnects from the MongoDB instance

func (*Client) Merge added in v0.0.2

func (c *Client) Merge(ctx context.Context, mergers ...[]EntityMerger) error

Merge attempts to merge each `EntityMerger` to the database.

It will print statistics once finished.

func (*Client) MigrateUp

func (c *Client) MigrateUp(migrationsFolder string) error

MigrateUp runs required migrations to get to the latest version.

This should be run before any other operations.

type Dispatch added in v0.0.2

type Dispatch gen.Dispatch

Dispatch implements EntityMerger

func (*Dispatch) Merge added in v0.0.2

func (d *Dispatch) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger.

type EntityMerger added in v0.0.2

type EntityMerger interface {
	// Merge merges the implementing entity to the database. It should call `onMerge` when finished.
	Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error
}

EntityMerger provide a means of merging an entity to the database.

type Event added in v0.0.2

type Event gen.Event

Event implements EntityMerger

func (*Event) Merge added in v0.0.2

func (e *Event) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger.

type Planet added in v0.0.2

type Planet struct {
	gen.Planet
	Biome   gen.Biome
	Hazards []gen.Hazard
}

Planet implements EntityMerger

func (*Planet) Merge added in v0.0.2

func (p *Planet) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger.

type PlanetSnapshot added in v0.0.2

type PlanetSnapshot struct {
	gen.PlanetSnapshot
	Event      *gen.EventSnapshot
	Statistics gen.SnapshotStatistic
}

PlanetSnapshot wraps all snapshots relevant for a planet.

type Snapshot added in v0.0.2

type Snapshot struct {
	gen.Snapshot
	WarSnapshot         gen.WarSnapshot
	AssignmentSnapshots []gen.AssignmentSnapshot
	PlanetSnapshots     []PlanetSnapshot
	Statistics          gen.SnapshotStatistic
}

Snapshot implements EntityMerger

func (*Snapshot) Merge added in v0.0.2

func (s *Snapshot) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger.

type War added in v0.0.2

type War gen.War

War implements EntityMerger

func (*War) Merge added in v0.0.2

func (w *War) Merge(ctx context.Context, tx *gen.Queries, onMerge onMergeFunc) error

Merge implements EntityMerger.

Directories

Path Synopsis
Code generated by sqlc-gen-enum.
Code generated by sqlc-gen-enum.
package main implements a custom `sqlc` generator.
package main implements a custom `sqlc` generator.
Package stats provides utilities for collecting and printing statistics
Package stats provides utilities for collecting and printing statistics

Jump to

Keyboard shortcuts

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