mongo

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT      = iota + 100 //100
	CONNECT                   //101
	INDEX_CREATE              //102
	SAVE                      //103
	COUNT                     //104
	UPDATE                    //105
	DELETE                    //106
	GET_CURSOR                //107
	PAGINATE                  //108
)

tags

Variables

View Source
var ConfigDefault = Config{
	ConnectionURI: "",
	Host:          "127.0.0.1",
	Port:          27017,
	Database:      "mg_demo",
}

ConfigDefault is the default config

Functions

func IndexText

func IndexText(key string, weight int) mongo.IndexModel

func IndexUnique

func IndexUnique(key string, value bool) mongo.IndexModel

func StringToBool

func StringToBool(value string) bool

func StringToInt

func StringToInt(value string) int

Types

type Config

type Config struct {
	// Connection string to use for DB. Will override all other authentication values if used
	//
	// Optional. Default is ""
	ConnectionURI string

	// Host name where the DB is hosted
	//
	// Optional. Default is "127.0.0.1"
	Host string

	// Port where the DB is listening on
	//
	// Optional. Default is 27017
	Port int

	// Server username
	//
	// Optional. Default is ""
	Username string

	// Server password
	//
	// Optional. Default is ""
	Password string

	// Database name
	//
	// Optional. Default is "fiber"
	Database string
}

Config defines the config for storage.

type Error

type Error struct {
	Code int
	Msg  string
}

type Log

type Log struct {
	ObjectID   primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
	Key        string             `json:"key" bson:"key"`
	Value      []byte             `json:"value" bson:"value"`
	Expiration time.Time          `json:"exp,omitempty" bson:"exp,omitempty"`
}

type Logger

type Logger struct {
	Storage *mongodb.Storage
}

func LoggerSettings

func LoggerSettings(mongo_uri string) *Logger

func (*Logger) Set

func (log *Logger) Set(key, value string)

type Mongo

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

func New

func New(config ...Config) *Mongo

func (*Mongo) CheckSaved

func (m *Mongo) CheckSaved(name string, filter primitive.D) bool

func (*Mongo) Collection

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

func (*Mongo) Connected

func (m *Mongo) Connected() bool

func (*Mongo) CreateIndex

func (m *Mongo) CreateIndex(name string, indexModel mongo.IndexModel) Error

func (*Mongo) Delete

func (m *Mongo) Delete(name string, filter primitive.D) Error

func (*Mongo) Get

func (m *Mongo) Get(name string, filter primitive.D, opts *options.FindOneOptions) *mongo.SingleResult

func (*Mongo) GetURI

func (m *Mongo) GetURI() string

func (*Mongo) Incr

func (m *Mongo) Incr(name, key, value string, filter primitive.D) Error

func (*Mongo) Paginate

func (m *Mongo) Paginate(name string, filter primitive.D, limit, page int64, x any) (paginate.PaginationData, Error)

func (*Mongo) Save

func (m *Mongo) Save(name string, data any) Error

func (*Mongo) Update

func (m *Mongo) Update(name string, filter primitive.D, data primitive.D) Error

type Schema

type Schema struct {
	Name        string
	IndexModels []mongo.IndexModel
	Mongo       *Mongo
	FilterID    primitive.D
}

func NewSchema

func NewSchema(name string) *Schema

func (*Schema) CheckSaved

func (s *Schema) CheckSaved() bool

func (*Schema) CreateIndex

func (s *Schema) CreateIndex()

func (*Schema) Delete

func (s *Schema) Delete() map[string]any

func (*Schema) Incr

func (s *Schema) Incr(key, value string) map[string]any

func (*Schema) Paginate

func (s *Schema) Paginate(filter primitive.D, limit, page int64, x any) mongopagination.PaginationData

func (*Schema) Save

func (s *Schema) Save(data any) map[string]any

func (*Schema) SetFilterID

func (s *Schema) SetFilterID(filter primitive.D) *Schema

func (*Schema) SetIndex

func (s *Schema) SetIndex(idx mongo.IndexModel) *Schema

func (*Schema) SetMongo

func (s *Schema) SetMongo(m *Mongo) *Schema

func (*Schema) Update

func (s *Schema) Update(data primitive.D) map[string]any

Jump to

Keyboard shortcuts

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