models

package
v0.0.0-...-f451b59 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXISTS  = iota
	DELETED = iota
	ALL     = iota
)

Variables

This section is empty.

Functions

func CloseUserStmts

func CloseUserStmts()

CloseUserStmts should be called when prepared SQL statements aren't needed anymore

func InitUserDataLayer

func InitUserDataLayer(db *sql.DB) error

InitUserDataLayer prepares SQL statements and assigns the passed in DB pointer

func UsersToJSON

func UsersToJSON(users []*User) ([]byte, error)

Convert multiple User objects to JSON

Types

type User

type User struct {
	LoginID     int          `json:"loginid"`
	Name        string       `json:"name, omitempty"`
	Email       nulls.String `json:"email”`
	Password    string       `json:"password" out:"false"`
	DeletedUser bool         `json:”deleted”`
	DelOn       nulls.Time   `json:”deletedon”`
}

func GetUsersByEmail

func GetUsersByEmail(email nulls.String, delFilter int) ([]*User, error)

Get Users by email

func GetUsersByName

func GetUsersByName(name string, delFilter int) ([]*User, error)

Get Users by name

func NewUser

func NewUser(loginID int, delFilter int) (*User, error)

Initialize and fill a User object from the DB

func UserFromJSON

func UserFromJSON(userJSON []byte) (*User, error)

Transform JSON into a User object

func (*User) Delete

func (user *User) Delete() error

Delete will remove the matching row from the DB

func (*User) GetByID

func (user *User) GetByID(loginID int, delFilter int) error

Fill User object with data from DB

func (*User) Insert

func (user *User) Insert() error

Insert User object to DB

func (*User) MarkDeleted

func (user *User) MarkDeleted(del bool, when nulls.Time) error

Mark a row as deleted and at time.Time

func (*User) PatchName

func (user *User) PatchName(name string) error

Update name only

func (*User) ToJSON

func (user *User) ToJSON() ([]byte, error)

Convert a User object to JSON

func (*User) Update

func (user *User) Update() error

Update User object in DB

type UserDataLayer

type UserDataLayer struct {
	DB         *sql.DB
	GetByID    *sql.Stmt
	Update     *sql.Stmt
	Insert     *sql.Stmt
	Delete     *sql.Stmt
	MarkDel    *sql.Stmt
	GetByName  *sql.Stmt
	GetByEmail *sql.Stmt
	PatchName  *sql.Stmt
	Init       bool
}

DataLayer is used to store prepared SQL statements

Jump to

Keyboard shortcuts

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