mango

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: AGPL-3.0 Imports: 5 Imported by: 0

README

mango

From a database management tools for optifur services, mango grew to become its own tooling module for use with mongodb databases.

mgo helper functions

The goal of the lib is to be able to generate simple request and pigination for mgo based on an input struct.

One function to generate pagination data based on mgo tags of the struct One function to generate filtering data based on mgo tags of the struct

filtering

Need to be able to filter, based on an input struct

  • the tag define the field name/path of the mgo data _id, username, friends.amount, etc... (The same way mongo does)
  • the tag should define the test opperator. It will be "fieldFromStruct OPERATOR fieldInDb" using mgo operators
  • default filtering is a $and, can be set to $or in function options

Tag format: mgo-filter:"fieldName,op:OPERATOR,omitempty" with:

  • fieldName the name of the field in mongo database, may be toto.titi for field titi inside toto
  • op the operator to use for comparision, eg $eq, $gt, etc
  • omitempty define the behaviour for empty/nil value. If omitempty is set, empty value or nil value will be ignored, else empty values will be used when filtering
pagination

Tag format:

  • mgo-paging:"limit,default: 10"
  • mgo-paging:"offset" // No default for offset, 0
  • mgo-paging:"sort,default: _id_" // Any field
  • mgo-paging:"sort-revert,default: _id_" // Any field

Nil pointer => use default value

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, cfg Config) (*mongo.Client, *mongo.Database)

New return a new data acces object

Types

type Config

type Config struct {
	URI  string `json:"uri"`
	Name string `json:"name"`
}

Config hold database configuration to connect

func (Config) String

func (c Config) String() string

String implements the stringer interfaces

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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