database

package
v0.0.0-...-4018599 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbErrorModalLackRequiredPrpty DbErrorCode = 20101
	DbErrorModalPrptyErr                      = 20102

	DbErrorInsertErr = 20201
	DbErrorDeleteErr = 20202
	DbErrorFindErr   = 20203
	DbErrorUpdateErr = 20204

	DbErrorUnknow = 29901
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Id          bson.ObjectId `json:"id" bson:"_id"`
	From        UserEmbed
	Message     string
	CreatedTime time.Time
}

type Database

type Database struct {
	// contains filtered or unexported fields
}

func New

func New() (*Database, error)

func (*Database) CheckEmailUnique

func (db *Database) CheckEmailUnique(email string) bool

func (*Database) CloseSession

func (db *Database) CloseSession()

func (*Database) CreateCommentForPostId

func (db *Database) CreateCommentForPostId(comment *Comment, postId bson.ObjectId) error

func (*Database) CreatePost

func (db *Database) CreatePost(post *Post) error

func (*Database) CreateUser

func (db *Database) CreateUser(user *User) error

/////////////////////////////////////////////////////////////////////////

func (*Database) GetPostByPostId

func (db *Database) GetPostByPostId(id bson.ObjectId) (*Post, error)

func (*Database) GetPostsByUserId

func (db *Database) GetPostsByUserId(id bson.ObjectId) ([]*Post, error)

func (*Database) GetUserByEmail

func (db *Database) GetUserByEmail(email string) (*User, error)

func (*Database) GetUserById

func (db *Database) GetUserById(id bson.ObjectId) (*User, error)

func (*Database) GetUsers

func (db *Database) GetUsers() ([]*User, error)

type DbError

type DbError struct {
	Code DbErrorCode
	Err  error
}

func (*DbError) Error

func (err *DbError) Error() string

type DbErrorCode

type DbErrorCode int

type Post

type Post struct {
	Id          bson.ObjectId `json:"id"    bson:"_id"`
	From        UserEmbed     `json:"from"  bson:"from"`
	Message     string
	CreatedTime time.Time
	UpdatedTime time.Time
	Comments    []Comment
}

type User

type User struct {
	Id       bson.ObjectId `json:"id"                  bson:"_id"`
	Email    string        `json:"email"               bson:"email"`
	Password string        `json:"password,omitempty"  bson:"password"` //when User convert to json string, password should be skipped
	Name     string        `json:"name"                bson:"name"`
}

type UserEmbed

type UserEmbed struct {
	Id   bson.ObjectId `json:"id" bson:"_id"`
	Name string        `json:"name" bson:"name"`
}

Jump to

Keyboard shortcuts

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