database

package
v0.0.0-...-3ee45e0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Ping() bool
	Insert(collectionName string, document Document) (bool, error)
	InsertMultiple(collectionName string, documents Documents) error
	Get(collectionName string, filter map[string]interface{}, document Document) error
	GetAll(collectionName string, filter map[string]interface{}, documents Documents) error
	GetWithLimit(collectionName string, filter map[string]interface{}, limit int64, documents Documents) error
	GetRandom(collectionName string, filter map[string]interface{}, limit int64, documents Documents) error
	GetUniqueValues(
		collectionName string,
		filter map[string]interface{},
		fieldName string,
	) ([]string, error)
	GetUniqueKeys(collectionName string, filter map[string]interface{}, fieldName string) ([]string, error)
	Delete(collectionName string, filter map[string]interface{}) (bool, error)
	DeleteAll(collectionName string, filter map[string]interface{}) (bool, error)
	RemoveCollection(collectionName string) error
	Update(collectionName string, filter map[string]interface{}, document Document) (bool, error)
	UpdateObject(collectionName string, filter map[string]interface{}, subDocument UpdateSubDocument) (bool, error)
	RemoveObject(collectionName string, filter map[string]interface{}, subDocument UpdateSubDocument) (bool, error)
	AppendToList(collectionName string, filter map[string]interface{}, subDocument NewSubDocument) (bool, error)
	RemoveFromList(collectionName string, filter map[string]interface{}, subDocument SubDocument) (bool, error)
}

type Document

type Document interface {
	Add(db Database) (bool, error)
	Get(db Database, filter map[string]interface{}) error
	Update(db Database, filter map[string]interface{}) (bool, error)
}

type Documents

type Documents interface {
	Add(db Database) error
	Get(db Database, filter map[string]interface{}) error
	GetWithLimit(db Database, filter map[string]interface{}, limit int64) error
	ToInterface() []interface{}
	Delete(db Database, filter map[string]interface{}) (bool, error)
}

type MongoDB

type MongoDB struct {
	*mongo.Database
	Client   *mongo.Client
	Logger   *log.Logger
	Host     string
	Port     int
	Username string
	Password string
	Name     string
	MaxConns int
	Timeout  int
}

func NewMongoDB

func NewMongoDB(
	logger *log.Logger,
	host string,
	port int,
	username string,
	password string,
	name string,
	maxConns int,
	timeout int,
) (*MongoDB, error)

func (*MongoDB) AppendToList

func (db *MongoDB) AppendToList(
	collectionName string,
	filter map[string]interface{},
	subDocument NewSubDocument,
) (bool, error)

func (*MongoDB) CloseDB

func (db *MongoDB) CloseDB()

func (*MongoDB) Delete

func (db *MongoDB) Delete(collectionName string, filter map[string]interface{}) (bool, error)

func (*MongoDB) DeleteAll

func (db *MongoDB) DeleteAll(collectionName string, filter map[string]interface{}) (bool, error)

func (*MongoDB) Get

func (db *MongoDB) Get(collectionName string, filter map[string]interface{}, document Document) error

func (*MongoDB) GetAll

func (db *MongoDB) GetAll(collectionName string, filter map[string]interface{}, documents Documents) error

func (*MongoDB) GetRandom

func (db *MongoDB) GetRandom(
	collectionName string,
	filter map[string]interface{},
	limit int64,
	documents Documents,
) error

func (*MongoDB) GetUniqueKeys

func (db *MongoDB) GetUniqueKeys(
	collectionName string,
	filter map[string]interface{},
	fieldName string,
) ([]string, error)

func (*MongoDB) GetUniqueValues

func (db *MongoDB) GetUniqueValues(
	collectionName string,
	filter map[string]interface{},
	field string,
) ([]string, error)

func (*MongoDB) GetWithLimit

func (db *MongoDB) GetWithLimit(
	collectionName string,
	filter map[string]interface{},
	limit int64,
	documents Documents,
) error

func (*MongoDB) Insert

func (db *MongoDB) Insert(collectionName string, document Document) (bool, error)

func (*MongoDB) InsertMultiple

func (db *MongoDB) InsertMultiple(collectionName string, documents Documents) error

func (*MongoDB) Ping

func (db *MongoDB) Ping() bool

func (*MongoDB) RemoveCollection

func (db *MongoDB) RemoveCollection(collectionName string) error

func (*MongoDB) RemoveFromList

func (db *MongoDB) RemoveFromList(
	collectionName string,
	filter map[string]interface{},
	subDocument SubDocument,
) (bool, error)

func (*MongoDB) RemoveObject

func (db *MongoDB) RemoveObject(
	collectionName string,
	filter map[string]interface{},
	subDocument UpdateSubDocument,
) (bool, error)

func (*MongoDB) Update

func (db *MongoDB) Update(
	collectionName string,
	filter map[string]interface{},
	document Document,
) (bool, error)

func (*MongoDB) UpdateObject

func (db *MongoDB) UpdateObject(
	collectionName string,
	filter map[string]interface{},
	subDocument UpdateSubDocument,
) (bool, error)

type NewSubDocument

type NewSubDocument interface {
	AddToList(db Database, filter map[string]interface{}) (bool, error)
}

type SubDocument

type SubDocument interface {
	RemoveFromList(db Database, filter map[string]interface{}) (bool, error)
}

type UpdateSubDocument

type UpdateSubDocument interface {
	Add(db Database, filter map[string]interface{}) (bool, error)
	Remove(db Database, filter map[string]interface{}) (bool, error)
}

Jump to

Keyboard shortcuts

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