mongo

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ServiceMongo = "mongo"
)

Variables

This section is empty.

Functions

func MapToBsonM

func MapToBsonM(m interface{}) (bson.M, error)

Types

type ConnectionConfig

type ConnectionConfig struct {
	Alias         string
	ConnectString string
	DBName        string
}

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

Sequence allows to create sequential numbers

current value is cached!

func (*Sequence) Current

func (s *Sequence) Current(ctx context.Context) (int, error)

Current returns current sequence value

func (*Sequence) Next

func (s *Sequence) Next(ctx context.Context) (int, error)

Next increments current value of Sequence and returns it return -1 on error

func (*Sequence) SetCurrent

func (s *Sequence) SetCurrent(ctx context.Context, value int) (int, error)

SetCurrent sets current value of Sequence to value

type SequenceProvider

type SequenceProvider struct {
	// contains filtered or unexported fields
}

func MongoSequenceForDB

func MongoSequenceForDB(db *mongo.Database) *SequenceProvider

func MongoSequenceForService

func MongoSequenceForService(ms *Service) *SequenceProvider

func (*SequenceProvider) ListSequences

func (msp *SequenceProvider) ListSequences(ctx context.Context, mask string) (map[string]int, error)

ListSequences returns sequences with names containing mask (case-insensitive)

func (*SequenceProvider) Prepare

func (msp *SequenceProvider) Prepare(eng *vivard.Engine, prov dep.Provider) (err error)

func (*SequenceProvider) Provide

func (msp *SequenceProvider) Provide() interface{}

func (*SequenceProvider) Sequence

func (msp *SequenceProvider) Sequence(ctx context.Context, name string) (vivard.Sequence, error)

Sequence returns Sequence object with given name

func (*SequenceProvider) Start

func (msp *SequenceProvider) Start(eng *vivard.Engine, prov dep.Provider) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(params ...any) (*Service, error)

New creates new mongo service params may be:

*mongo.Database (should be first)
db-name (connect string will be build for the local host)
pair connect string - db-name
ConnectionConfig object

func (*Service) DB

func (ms *Service) DB() *mongo.Database

func (*Service) GetDefaultMongo

func (ms *Service) GetDefaultMongo(ctx context.Context) (*mongo.Database, error)

GetDefaultMongo returns default database

func (*Service) GetMongo

func (ms *Service) GetMongo(ctx context.Context, alias string) (*mongo.Database, error)

GetMongo returns database with given alias

func (*Service) Prepare

func (ms *Service) Prepare(eng *vivard.Engine, prov dep.Provider) (err error)

func (*Service) Provide

func (ms *Service) Provide() interface{}

func (*Service) Start

func (ms *Service) Start(eng *vivard.Engine, prov dep.Provider) error

func (*Service) With

func (ms *Service) With(db *mongo.Database) *Service

Jump to

Keyboard shortcuts

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