database

package
v0.0.0-...-43a32cb Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disconnect

func Disconnect()

Closing the database connection, correctly

Types

type Credentials

type Credentials struct {
	User     string
	Password string
	DbName   string
}

type Database

type Database interface {
	Create(p Product) error
	ReadById(p Product) Product
	ReadByWholesalers(name string) []Product
	Delete(p Product) error
}

Interface useful for mocking test, or if need change database

type MongoDb

type MongoDb struct {
	Log *logrus.Logger
	// contains filtered or unexported fields
}

My database struct

var (
	Db *MongoDb
)

vars needed for only created one instance for my access to the database

func Connect

func Connect(dburi, name string, log *logrus.Logger, credentials ...Credentials) (*MongoDb, error)

Connect give you a connection to the database, only one instance will be create, to connect with mongo database, we need the URI where are the DB, the user name and password, and will return the instance with an active connection or an error

func (*MongoDb) Create

func (db *MongoDb) Create(p Product) error

Inserting product in the database, only when is a new product or when price change, is can't do this, return error

func (*MongoDb) Delete

func (db *MongoDb) Delete(p Product) error

Delete a product from DB, if can't do this, return an error. And will print when not found matchs

func (*MongoDb) DeleteWhosaler

func (m *MongoDb) DeleteWhosaler(w Wholesalers) error

Delete a product from DB, if can't do this, return an error. And will print when not found matchs

func (*MongoDb) FindWholesalers

func (m *MongoDb) FindWholesalers() []Wholesalers

Reading from database and returning all wholesalers

func (*MongoDb) GetAllProducts

func (db *MongoDb) GetAllProducts() []Product

GetAllProducts return all products from database

func (*MongoDb) GetWhosalerById

func (m *MongoDb) GetWhosalerById(w Wholesalers) Wholesalers

Reading from database, a product identified with his ID

func (*MongoDb) GetWhosalerName

func (m *MongoDb) GetWhosalerName(w Wholesalers) Wholesalers

Reading from database, a product identified with his ID

func (*MongoDb) InsertWholesaer

func (db *MongoDb) InsertWholesaer(w Wholesalers) error

func (*MongoDb) Ping

func (db *MongoDb) Ping() error

Ping sends a ping command to verify that the client can connect to the deployment.

func (*MongoDb) ReadById

func (db *MongoDb) ReadById(p Product) Product

Reading from database, a product identified with his ID

func (*MongoDb) ReadByMongoId

func (db *MongoDb) ReadByMongoId(p Product) Product

Reading from database, a product identified with his ID

func (*MongoDb) ReadByWholesalers

func (db *MongoDb) ReadByWholesalers(name string) []Product

Reading from database and returning all products from one wholesaler

func (*MongoDb) SearchByName

func (db *MongoDb) SearchByName(p Product) []Product

func (*MongoDb) SearchSimilars

func (db *MongoDb) SearchSimilars(p Product) []Product

func (*MongoDb) UpdateWholesaler

func (db *MongoDb) UpdateWholesaler(w Wholesalers) error

type Product

type Product struct {
	Id_         primitive.ObjectID `bson:"_id,omitempty"`
	Id          string             `bson:"id,omitempty"`
	Name        string             `bson:"name,omitempty"`
	Image       string
	Description string
	Price       []Value `bson:"prices,omitempty"`
	Stock       string
	Wholesaler  string
}

Data product needed, not mather what wholesaler get data

type Value

type Value struct {
	Price float64   `bson:"price,omitempty"`
	Date  time.Time `bson:"date,omitempty"`
}

type Wholesalers

type Wholesalers struct {
	Id           primitive.ObjectID `bson:"_id,omitempty"`
	Login        string             `json:"login" bson:"login"`
	User         string             `json:"user" bson:"user"`
	Pass         string             `json:"pass" bson:"pass"`
	Searchpage   string             `json:"searchpage" bson:"searchpage"`
	Name         string             `json:"name" bson:"name"`
	EndPhrase    string             `json:"endphrase"`
	EndPhraseDiv string             `json:"endphrasediv"`
}

Jump to

Keyboard shortcuts

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