database

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 10 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 struct {
	Db *sql.DB
}

func Init

func Init(CDB config.DatabaseConfig, sqlFile string) (db *DataBase, err error)

Init Params: CDB config.DatabaseConfig, sqlFile string Return: db *DataBase, error Description: try to connect to DataBase.

func (*DataBase) CreateForum

func (db *DataBase) CreateForum(forum models.Forum) (forumQuery models.Forum, checkUnique bool, err error)

CreateForum Params: forum model Return: model forum, checkUnique flag, error Description: insert forum into Forum table

func (*DataBase) CreatePost

func (db *DataBase) CreatePost(posts []models.Post, thread models.Thread, timeNow time.Time) (postQuery []models.Post, check int, err error)

CreatePost Params: post models array, thread model, time of poosts created Return: inserted post models, check flag of existence of parental posts and error Description: insert posts into table Post

func (*DataBase) CreateTables

func (db *DataBase) CreateTables(sqlFile string) error

CreateTables Params: sqlFile string Return: error Description: get sqlFile with create tables commands and execute it

func (*DataBase) CreateThread

func (db *DataBase) CreateThread(thread models.Thread) (threadQuery models.Thread, checkUnique bool, err error)

CreateThread Params: models.Thread Returns: created thread, checkUnique flag and error Description: get thread model and create thread record in Thread table

func (*DataBase) CreateUser

func (db *DataBase) CreateUser(user models.User) (users []models.User, checkUnique bool, err error)

CreateUser Params: models.User Returns: array of users if they have same nickname or email, checkUnique flag and error Description: get user model and insert into databse

func (*DataBase) DeleteForum

func (db *DataBase) DeleteForum(slug string) (err error)

DeleteForum Params: slug string Return: error Description: delete forum by slug

func (*DataBase) GetForumBySlug

func (db *DataBase) GetForumBySlug(slug string) (forum models.Forum, checkFindForum bool, err error)

GetForumBySlug Params: slug string Return: forum model, checkFindForum flag, error Description: select forum by slug

func (*DataBase) GetPostById

func (db *DataBase) GetPostById(id int) (post models.Post, checkFindPost bool, err error)

GetPostById Params: id post Return: post model, checkFindPost flag, error Description: select post by id in Post table

func (*DataBase) GetPostsByThread

func (db *DataBase) GetPostsByThread(thread models.Thread, limitStr string, sinceStr string, sortStr string, descStr string) (posts []models.Post, err error)

GetPostsByThread Params: thread models.Thread, limitStr string, sinceStr string, sortStr string, descStr string Return: selected post models array and error Description: select posts from thread

func (*DataBase) GetThreadById

func (db *DataBase) GetThreadById(slugOrId string) (thread models.Thread, checkFindThread bool, err error)

GetThreadById Params: string Returns: selected thread model, checkFindThread flag and error Description: get slug/id of thread and select thread from Thread table

func (*DataBase) GetThreadsByForum

func (db *DataBase) GetThreadsByForum(title string, limitStr string, sinceStr string, descStr string) (threads []models.Thread, err error)

GetThreadsByForum Params: string, string, string, string Returns: selected thread models array and error Description: get forum title, limit, since, desc and select threads from Thread table

func (*DataBase) GetUserByNickname

func (db *DataBase) GetUserByNickname(nickname string) (user models.User, checkFindUser bool, err error)

GetUserByNickname Params: string Returns: checkFindUser flag and error Description: get nickname and return user from databse

func (*DataBase) GetUsersByForum

func (db *DataBase) GetUsersByForum(title string, limitStr string, sinceStr string, descStr string) (users []models.User, err error)

GetUsersByForum Params: string, string, string, string Returns: array of users from database and error Description: get forum title, limit, since, desc

func (*DataBase) InsertOrUpdateVoteUser

func (db *DataBase) InsertOrUpdateVoteUser(vote models.Vote, thread *models.Thread) (err error)

InsertOrUpdateVoteUser Params: models.Vote, *models.Thread Returns: error Description: get vote, thread and insert or update into table Vote in database

func (*DataBase) ServiceClear

func (db *DataBase) ServiceClear() (err error)

ServiceClear Params: sqlFile string Return: error Description: truncate all tables in database

func (*DataBase) UpdateFieldsForum

func (db *DataBase) UpdateFieldsForum(slug string, number int, field string) (err error)

UpdateFieldsForum Params: slug string, number of posts, field(threads or posts) Return: error Description: update thread or post count

func (*DataBase) UpdateThread

func (db *DataBase) UpdateThread(threadNew models.Thread, threadOld models.Thread) (threadRes models.Thread, err error)

UpdateThread Params: models.Thread, models.Thread Returns: updated thread model and error Description: get threadNew model, threadOld model and update record in Thread table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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