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.