db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: GPL-3.0 Imports: 12 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 UpsertDocs

func UpsertDocs[T any](ctx context.Context, c *Client, provider *DocsProvider[T])

UpsertDocs inserts or updates a list of documents based on their IDs.

Documents are matched by ID ("_id"). If a document with that ID already exists, it is updated. If it doesn't exist, it is inserted.

If an error occurs during upsert of one of the documents, processing continues. Thus, no error is returned.

Types

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, database string, logger *log.Logger) (*Client, error)

New creates a new client and connects it to the DB

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect disconnects from the MongoDB instance

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 CollectionName

type CollectionName string

CollectionName is the name of a collection in the MongoDB database.

const (
	// CollPlanets is the collection name for Planets
	CollPlanets CollectionName = "planets"
	// CollCampaigns is the collection name for Campaigns
	CollCampaigns CollectionName = "campaigns"
	// CollDispatches is the collection name for Dispatches
	CollDispatches CollectionName = "dispatches"
	// CollEvents is the collection name for Events
	CollEvents CollectionName = "events"
	// CollAssignments is the collection name for Assignments
	CollAssignments CollectionName = "assignments"
	// CollWars is the collection name for Wars
	CollWars CollectionName = "wars"
	// CollSnapshots is the collection name for Snapshots
	CollSnapshots CollectionName = "snapshots"
)

type DocWrapper

type DocWrapper[T any] struct {
	DocID    any
	Document T
}

DocWrapper holds the document to be processed plus its document ID.

T should be the Document type.

type DocsProvider

type DocsProvider[T any] struct {
	CollectionName CollectionName
	Docs           []DocWrapper[T]
}

DocsProvider wraps collection name and document slice for further processing.

T should be the Document type.

Directories

Path Synopsis
Package structs contains the types required for MongoDB mapping
Package structs contains the types required for MongoDB mapping

Jump to

Keyboard shortcuts

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