database

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMongoDBURI

func IsMongoDBURI(dsn string) bool

IsMongoDBURI checks if the provided DSN is a MongoDB URI

Types

type MongoDBConnection

type MongoDBConnection struct {
	Client   *mongo.Client
	Database *mongo.Database
	// contains filtered or unexported fields
}

MongoDBConnection wraps a MongoDB client and database

func ConnectMongoDB

func ConnectMongoDB(uri string, logger *slog.Logger) (*MongoDBConnection, error)

ConnectMongoDB connects to MongoDB using the provided URI The URI should be in the format: mongodb://[user:pass@]host[:port]/database[?options] or mongodb+srv://... for Atlas clusters

func ConnectMongoDBFromEnv

func ConnectMongoDBFromEnv(logger *slog.Logger) (*MongoDBConnection, error)

ConnectMongoDBFromEnv reads MONGODB_URI or MONGO_URI env variable and connects to MongoDB. Returns (nil, nil) if no MongoDB URI is configured.

func (*MongoDBConnection) Close

func (m *MongoDBConnection) Close(ctx context.Context) error

Close closes the MongoDB connection

func (*MongoDBConnection) Collection

func (m *MongoDBConnection) Collection(name string) *mongo.Collection

Collection returns a collection handle for the specified collection name

func (*MongoDBConnection) DatabaseName added in v0.1.1

func (m *MongoDBConnection) DatabaseName() string

DatabaseName returns the name of the connected database.

func (*MongoDBConnection) RawMessagesCollection added in v0.1.1

func (m *MongoDBConnection) RawMessagesCollection() *mongo.Collection

RawMessagesCollection returns the raw_messages collection handle used for message retention.

func (*MongoDBConnection) TestRunsCollection

func (m *MongoDBConnection) TestRunsCollection() *mongo.Collection

TestRunsCollection returns the test_runs collection handle

Jump to

Keyboard shortcuts

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