mongo

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

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

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FieldKey = "bson"

FieldKey is the struct tag for field names

View Source
var PageSize = 100000

PageSize if the default page size applied if none supplied for search

Functions

func MapToStruct

func MapToStruct(m map[string]interface{}, out interface{}) error

MapToStruct converts map to given struct

func StructToAddrMap

func StructToAddrMap(in interface{}, tag string) (map[string]reflect.Value, error)

StructToAddrMap returns a map of fielname(or tag) to field variable reference if not struct or pointer to struct it fails

func StructToMap

func StructToMap(in interface{}, tag string, withValue bool) (m map[string]interface{}, err error)

StructToMap converts a struct to map of string to interface Its uses the tag 'map' or given `tag` to check the name to be used if the value is zero value and withValue is true no key is added if there are embeded structs they are also traversed recursively in case of embeded structs having same field name and struct tag the last field in order will be considered

Types

type DB

type DB struct {
	*mgo.Database
}

DB Database implementation for mongo

func New

func New(host string, port int, db string, connectionTimeout time.Duration) (*DB, error)

New creates a new DB instance

func (*DB) Delete

func (db *DB) Delete(name string, ID string, result interface{}) error

Delete delets a row given id and table name

func (*DB) Get

func (db *DB) Get(name string, filter interface{}, result interface{}, pageNum int, pageSize int) error

Get fiters the table given filter and pagination logic Current implementation does not support search with other types of predicates The request is paginated with pagenum and page size parameters

func (*DB) Insert

func (db *DB) Insert(name string, values ...interface{}) error

Insert to insert a doecument ot the database

func (*DB) Update

func (db *DB) Update(name string, ID string, update interface{}, result interface{}) error

Update updates rows given filter

type StructField

type StructField struct {
	Type  reflect.StructField
	Value reflect.Value
}

StructField represents a struct field with field type and value

Jump to

Keyboard shortcuts

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