base

package
v0.0.2-0...-db2304f Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbNameUser     = "test"
	CollectionUser = "users"
)

Variables

View Source
var (
	ErrorInvalidObjectId = errors.New("invalid objectId")
)

Functions

func DeleteUserByID

func DeleteUserByID(id bson.ObjectId) error

func ExistUserByID

func ExistUserByID(id bson.ObjectId) (bool, error)

func GetUserSessionAndCollection

func GetUserSessionAndCollection() (*mgo.Session, *mgo.Collection)

func UpdateUser

func UpdateUser(selector interface{}, user *User) error

Update finds a single document matching the provided selector document and modifies it according to the update document. If the session is in safe mode (see SetSafe) a ErrNotFound error is returned if a document isn't found, or a value of type *LastError when some other error is detected.

Relevant documentation:

http://www.mongodb.org/display/DOCS/Updating
http://www.mongodb.org/display/DOCS/Atomic+Operations

func UpdateUserAll

func UpdateUserAll(selector interface{}, user *User) (*mgo.ChangeInfo, error)

UpdateAll finds all documents matching the provided selector document and modifies them according to the update document. If the session is in safe mode (see SetSafe) details of the executed operation are returned in info or an error of type *LastError when some problem is detected. It is not an error for the update to not be applied on any documents because the selector doesn't match.

Relevant documentation:

http://www.mongodb.org/display/DOCS/Updating
http://www.mongodb.org/display/DOCS/Atomic+Operations

func UpdateUserByID

func UpdateUserByID(id bson.ObjectId, user *User) error

func UpdateUserByIDAndEntityMap

func UpdateUserByIDAndEntityMap(id bson.ObjectId, updateMap map[string]interface{}) error

Types

type User

type User struct {
	ID       bson.ObjectId `bson:"_id" json:"id"`
	UserName string        `bson:"user_name" json:"user_name,omitempty" valid:"required~first name is blank"`
	Email    string        `bson:"email" json:"email,omitempty" valid:"required,email"`
	Password string        `bson:"password" json:"password,omitempty" valid:"required"`
	Ct       int64         `bson:"ct" json:"ct"`
	Mt       int64         `bson:"mt" json:"mt"`
	Deleted  int           `bson:"deleted" json:"-"`
}

func GetOneUserByQuery

func GetOneUserByQuery(query map[string]interface{}) (*User, error)

func GetUserByID

func GetUserByID(id bson.ObjectId) (*User, error)

func ListAllUserByQuery

func ListAllUserByQuery(query map[string]interface{}) ([]*User, error)

func ListAllUserByQueryWithOffsetAndLimit

func ListAllUserByQueryWithOffsetAndLimit(query map[string]interface{}, offset, limit int) ([]*User, error)

func ListAllUserByQueryWithOrder

func ListAllUserByQueryWithOrder(query map[string]interface{}, offset, limit int, order ...string) ([]*User, error)

func NewUser

func NewUser() *User

func (*User) Insert

func (user *User) Insert() error

Jump to

Keyboard shortcuts

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