database

package
v0.0.0-...-7c2803f Latest Latest
Warning

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

Go to latest
Published: Mar 19, 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 TenDatabase

type TenDatabase struct {
	DB      *mongo.Database
	Client  *mongo.Client
	Context context.Context
}

TenDatabase is a wrapper for the mongo-go-driver.

func New

func New(connection, dbname string) (*TenDatabase, error)

New creates a new wrapper for the mongo-go-driver.

func (*TenDatabase) Close

func (d *TenDatabase) Close()

Close closes the mongo-go-driver connection.

func (*TenDatabase) CountPost

func (d *TenDatabase) CountPost(condition interface{}) string

CountPost returns the post count

func (*TenDatabase) CountUser

func (d *TenDatabase) CountUser() string

CountUser returns the user count

func (*TenDatabase) CreatePost

func (d *TenDatabase) CreatePost(post *model.Post) *model.Post

CreatePost creates a post.

func (*TenDatabase) CreateUser

func (d *TenDatabase) CreateUser(user *model.User) error

CreateUser creates a user.

func (*TenDatabase) DeletePostByID

func (d *TenDatabase) DeletePostByID(id primitive.ObjectID) error

DeletePostByID deletes a post by its id.

func (*TenDatabase) DeleteUserByID

func (d *TenDatabase) DeleteUserByID(id primitive.ObjectID) error

DeleteUserByID deletes a user by its id.

func (*TenDatabase) GetPostByID

func (d *TenDatabase) GetPostByID(id primitive.ObjectID) *model.Post

GetPostByID returns the post by the given id or nil.

func (*TenDatabase) GetPosts

func (d *TenDatabase) GetPosts(paging *model.Paging) []*model.Post

GetPosts returns all posts. start, end int, order, sort string

func (*TenDatabase) GetUserByIDs

func (d *TenDatabase) GetUserByIDs(ids []primitive.ObjectID) []*model.User

GetUserByIDs returns the user by the given id or nil.

func (*TenDatabase) GetUserByName

func (d *TenDatabase) GetUserByName(name string) *model.User

GetUserByName returns the user by the given name or nil.

func (*TenDatabase) GetUsers

func (d *TenDatabase) GetUsers(paging *model.Paging) []*model.User

GetUsers returns all users. start, end int, order, sort string

func (*TenDatabase) UpdatePost

func (d *TenDatabase) UpdatePost(post *model.Post) *model.Post

UpdatePost updates a post.

Jump to

Keyboard shortcuts

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