v0.0.0-...-dbbace4 Latest Latest

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

Go to latest
Published: Dec 16, 2018 License: LGPL-3.0 Imports: 6 Imported by: 1



Package db implements model.db interface. It contains everything that needed by API to interact with database.



This section is empty.


This section is empty.


This section is empty.


type Config

type Config struct {
	DBAddress    string `json:"DBAddress,"`
	MaxOpenConns int    `json:"MaxOpenConns,int"`

Config is stuct for database configuration.

type Handler

type Handler struct {
	DB *sqlx.DB

	CreateUser        *sqlx.NamedStmt
	CreateAd          *sqlx.NamedStmt
	UpdateUser        *sqlx.NamedStmt
	UpdateAd          *sqlx.NamedStmt
	ReadAds           *sqlx.NamedStmt
	SearchAds         *sqlx.NamedStmt
	ReadAdsOfUser     *sqlx.Stmt
	ReadAd            *sqlx.Stmt
	ReadUserWithID    *sqlx.Stmt
	ReadUserWithEmail *sqlx.Stmt
	DeleteUser        *sqlx.Stmt
	DeleteAd          *sqlx.Stmt

Handler is used to store database connection and implements database interface needed by API.

func InitConnDB

func InitConnDB(cfg Config) (*Handler, error)

InitConnDB initiates connection to database and prepare statements for interaction with database.

func (*Handler) EditAd

func (h *Handler) EditAd(ad *model.AdItem) (int64, error)

EditAd updates information about ad with ID provided from function argument.

func (*Handler) EditUser

func (h *Handler) EditUser(user *model.User) (int64, error)

EditUser updates User with ID provided from function argument.

func (*Handler) GetAd

func (h *Handler) GetAd(adID int64) (*model.AdItem, error)

GetAd returns model.AdItem struct with such ID.

func (*Handler) GetAds

func (h *Handler) GetAds(sp *model.SearchParams) ([]*model.AdItem, error)

GetAds returns slice of model.AdItem from database based on incoming filters.

func (*Handler) GetAdsOfUser

func (h *Handler) GetAdsOfUser(userID int64) ([]*model.AdItem, error)

GetAdsOfUser returns slice of model.AdItem with such user from database.

func (*Handler) GetUserWithEmail

func (h *Handler) GetUserWithEmail(email string) (*model.User, error)

GetUserWithEmail returns model.User struct with such email.

func (*Handler) GetUserWithID

func (h *Handler) GetUserWithID(userID int64) (*model.User, error)

GetUserWithID returns model.User struct with such ID.

func (*Handler) NewAd

func (h *Handler) NewAd(ad *model.AdItem) (int64, error)

NewAd creates a new row in "ads" table in database.

func (*Handler) NewUser

func (h *Handler) NewUser(user *model.User) (int64, error)

NewUser adds new User to database if it is possible.

func (*Handler) RemoveAd

func (h *Handler) RemoveAd(adID int64) (int64, error)

RemoveAd deletes ad with such ID from database.

func (*Handler) RemoveUser

func (h *Handler) RemoveUser(userID int64) (int64, error)

RemoveUser deletes user with such ID from database.

Jump to

Keyboard shortcuts

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