mongolib

package
v0.0.0-...-2a7ebff Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 2000 * time.Millisecond

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	Uri      string `validation:"required"`
	Database string `validation:"required"`
	Timeout  time.Duration
}

func ClientOptionsFromEnvConfig

func ClientOptionsFromEnvConfig(cfg EnvClientConfig) ClientOptions

type CollectionDef

type CollectionDef struct {
	Name       string
	Timeseries *TimeseriesDef
	Indexes    []IndexDef
}

type Connection

type Connection struct {
	Client *mongo.Client
	DB     *mongo.Database
	Logger *slog.Logger
	// contains filtered or unexported fields
}

func Connect

func Connect(config ClientOptions) (conn *Connection, err error)

func (*Connection) Coll

func (c *Connection) Coll(name string) *mongo.Collection

func (*Connection) DefineCollections

func (c *Connection) DefineCollections(defs []CollectionDef) error

func (*Connection) InsertOne

func (c *Connection) InsertOne(coll string, data any) (res *mongo.InsertOneResult, err error)

func (*Connection) UpsertOne

func (c *Connection) UpsertOne(coll string, filter any, data any) (res *mongo.UpdateResult, err error)

type EnvClientConfig

type EnvClientConfig struct {
	Uri      string        `env:"MONGODB_URI" validate:"required"`
	Database string        `env:"MONGODB_DATABASE" validate:"required"`
	Timeout  time.Duration `env:"MONGODB_TIMEOUT" validate:"numeric"`
}

type IndexDef

type IndexDef struct {
	Fields bson.D
	Unique bool
}

type TimeseriesDef

type TimeseriesDef struct {
	TimeField   string
	MetaField   string
	Granularity string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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