model

package
v0.0.0-...-86d81c4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBName = "docker"
	CName  = "users"
)

DBName is name of the database and CName is the name of document collection

Variables

This section is empty.

Functions

func CreateDBSession

func CreateDBSession() *mgo.Session

CreateDBSession creates mgo session

func CreateInitDocument

func CreateInitDocument(m *mgo.Collection)

CreateInitDocument initializes collection with 50 users

func GetSession

func GetSession() *mgo.Session

GetSession will create a session if doesn't exist else will return existing session

func InitDB

func InitDB() *mgo.Collection

InitDB is to be used in main.go to initialize database

func Query

func Query(m *mgo.Collection, query interface{}) interface{}

Query conducts search on mongodb collection

Types

type Context

type Context struct {
	Session *mgo.Session
}

Context is an mgo session

func GetContext

func GetContext() *Context

GetContext get mgo collection context

func MongoSetup

func MongoSetup() *Context

MongoSetup returns context

func (*Context) Close

func (c *Context) Close()

Close the context session

func (*Context) DBCollection

func (c *Context) DBCollection() *mgo.Collection

DBCollection returns mgo collection

type Model

type Model struct {
	ID        string
	FirstName string
	LastName  string
	Email     string
	Gender    string
}

Model is a mgo struct data type

func New

func New() *Model

New returns new Model

func (*Model) Create

func (m *Model) Create() Model

Create method for the store that creates another Model

func (*Model) Delete

func (m *Model) Delete() (Model, error)

Delete method removes the given Model

func (*Model) GetAll

func (m *Model) GetAll() ([]Model, error)

GetAll method returns all the Models

func (*Model) GetByID

func (m *Model) GetByID() (Model, error)

GetByID method returns Model with given id

func (*Model) Update

func (m *Model) Update() (Model, error)

Update method updates the given Model

type Models

type Models []Model

Models type which is slice of Model

type Store

type Store interface {
	Create(m *Model) Model
	GetAll() ([]Model, error)
	GetByID(m *Model) (Model, error)
	Update(m *Model) (Model, error)
	Delete(m *Model) (Model, error)
}

Store has CRUD methods for mongodb

type UserModel

type UserModel struct {
	ID        int    `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Gender    string `json:"gender"`
}

UserModel Struct is the model for the app

type UserModels

type UserModels []UserModel

UserModels represents a slice of user models

func GetModels

func GetModels() UserModels

GetModels returns user models

type Users

type Users struct {
	ID        int    `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Gender    string `json:"gender"`
}

Users Struct is the model for the app

func GetUserByID

func GetUserByID(ID int) (*Users, error)

GetUserByID returns a user by the given id

func GetUsers

func GetUsers() []Users

GetUsers returns a list of users for the index route

Jump to

Keyboard shortcuts

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