mgom

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 9 Imported by: 0

README

mgom

Mgom is a mongo ODM for Go //This is not ready for production //i am still working on it

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

View Source
const Version = "0.0.2"

Variables

This section is empty.

Functions

func StringToBool

func StringToBool(value string) bool

func StringToInt

func StringToInt(value string) int

Types

type Collection

type Collection struct {
	Name  string
	Mg    *MongoInstance
	Index []IndexFactory
}

func NewCollection

func NewCollection(name string, mg *MongoInstance) *Collection

func (*Collection) CreateIndex

func (c *Collection) CreateIndex() Error

func (*Collection) GetCollection

func (c *Collection) GetCollection() *mongo.Collection

func (*Collection) SetIndex

func (c *Collection) SetIndex(idx []IndexFactory) *Collection

type Document

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

func NewDocument

func NewDocument(c *Collection) *Document

func (*Document) CheckSaved

func (d *Document) CheckSaved() bool

check if docs already saved in database

func (*Document) CountAll

func (d *Document) CountAll() (int64, Error)

func (*Document) Delete

func (d *Document) Delete() Error

func (*Document) Get

func (d *Document) Get() *mongo.SingleResult

func (*Document) GetCursor

func (d *Document) GetCursor(limit int64) (*mongo.Cursor, Error)

func (*Document) Incr

func (d *Document) Incr(key string, value string) Error

func (*Document) Paginate

func (d *Document) Paginate(limit, page int64, x any) (paginate.PaginationData, Error)

func (*Document) PaginateWithSelect

func (d *Document) PaginateWithSelect(limit, page int64) paginate.PagingQuery

func (*Document) Save

func (d *Document) Save() Error

func (*Document) SetCollection

func (d *Document) SetCollection(c *Collection) *Document

func (*Document) SetData

func (d *Document) SetData(a any) *Document

func (*Document) SetFields

func (d *Document) SetFields(f primitive.D) *Document

func (*Document) SetFilter

func (d *Document) SetFilter(f primitive.D) *Document

func (*Document) SetUpdate

func (d *Document) SetUpdate(a primitive.D) *Document

func (*Document) Update

func (d *Document) Update() Error

type Error added in v0.0.2

type Error struct {
	Code int
	Msg  string
}

type IndexFactory

type IndexFactory struct {
	T      IndexType
	Values map[string]string
}

func (*IndexFactory) CreateIndex

func (x *IndexFactory) CreateIndex(c *Collection) Error

type IndexText

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

func (*IndexText) Set

func (x *IndexText) Set()

type IndexType

type IndexType int
const (
	IdxUNIQUE IndexType = iota
	IdxTEXT
)

enums

type IndexUnique

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

func (*IndexUnique) Set

func (x *IndexUnique) Set()

type KV

type KV struct {
	Key   string
	Value string
}

type MongoInstance

type MongoInstance struct {
	DbName    string
	BaseUrl   string
	Uri       string
	Context   context.Context
	Client    *mongo.Client
	Db        *mongo.Database
	Connected bool
}

MongoInstance contains the Mongo client and database objects

func NewMongoInstance

func NewMongoInstance(dbName, baseUrl string) *MongoInstance

func (*MongoInstance) Connect

func (mg *MongoInstance) Connect() Error

func (*MongoInstance) GetCollection

func (mg *MongoInstance) GetCollection(value string) *mongo.Collection

func (*MongoInstance) ListDatabaseNames

func (mg *MongoInstance) ListDatabaseNames() Error

func (*MongoInstance) SetBaseUrl

func (mg *MongoInstance) SetBaseUrl(value string) *MongoInstance

func (*MongoInstance) SetDbName

func (mg *MongoInstance) SetDbName(value string) *MongoInstance

func (*MongoInstance) SetUri

func (mg *MongoInstance) SetUri() *MongoInstance

type QType

type QType int
const (
	QFilter QType = iota
	QSet
	QSearch
	QInc
)

type Query

type Query struct {
	QType QType
	Data  primitive.D
	Kv    KV
}

func (*Query) Get

func (q *Query) Get() primitive.D

Jump to

Keyboard shortcuts

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