database

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: GPL-3.0 Imports: 9 Imported by: 6

Documentation

Overview

database package contains helper functions related to database connection that remove boilerplate code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDatabaseOptions

func CreateDatabaseOptions(awsConfig aws.Config, transportCtx context.Context, databaseSecretARN, databaseEndpoint, databaseName string) (*options.ClientOptions, error)

CreateDatabaseOptions fetches the databaseSecret containing "username" and "password" from SecretsManager and constructs the mongo client options. The calling instance needs to have IAM access to the action "secretsmanager:GetSecretValue" on the provided databaseSecretARN.

func SetupIndexes added in v0.1.1

func SetupIndexes(collection *mongo.Collection, transportCtx context.Context, indexes []Index) error

SetupIndexes adds the provided struct as indexes to the specified collection. indexes expects a struct with fields annotated with `bson:"key"` tags using the sortOrder as value (ASC = 1; DESC = -1;) This may be called on every initialization of the mongo client with the indexes required for the current endpoint. Mongodb handles applying indexModels idempotently and should therefore only cause a minimal overhead.

Types

type Index added in v0.1.1

type Index struct {
	// Sorted structure containing all field names forming the compoundKeys for the index.
	// The first key can be used to efficiently query on its own OR combined with the further keys
	// however queries that only go to the further keys, do not profit from the index performance.
	FieldNames []string
	// SortingOrder used for all field names.
	SortingOrder int
	// Tag identifying wheter the combination of all FieldNames is enforced to be unique.
	Unique bool
}

Represents a structure for one mongo index.

Jump to

Keyboard shortcuts

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