base

package
v0.0.0-...-a3a3ab8 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionUser = "users"
)

Variables

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

	MongoSession *mgo.Session
)

Functions

func DeleteUserByID

func DeleteUserByID(id string) error

func ExistUserByID

func ExistUserByID(id string) (bool, error)

func GetSessionAndCollection

func GetSessionAndCollection(collection string) (*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 interface{}, user *User) error

func UpdateUserByIDAndEntityMap

func UpdateUserByIDAndEntityMap(id interface{}, 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"`
	Email     string        `bson:"email" json:"email,omitempty"`
	Password  string        `bson:"password" json:"password,omitempty"`
	CreatedAt time.Time     `bson:"created_at" json:"created_at" time_format:"2006-01-02 15:04:05"`
	UpdatedAt time.Time     `bson:"updated_at" json:"updated_at" time_format:"2006-01-02 15:04:05"`
	Deleted   int           `bson:"deleted" json:"-"`
}

func GetOneUserByQuery

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

func GetUserByID

func GetUserByID(id interface{}) (*User, error)

func ListAllUserByQuery

func ListAllUserByQuery(query map[string]interface{}) ([]*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