model

package
v0.0.0-...-8f9fda8 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	gorm.Model
	UserID       uint `gorm:"index"` // Foreign key (belongs to)
	ClientKey    string
	ClientSecret string
	Description  string
}

Client is a mqtt client model

func (*Client) AfterFind

func (c *Client) AfterFind()

AfterFind invokes required after loading a record from the database.

func (*Client) BeforeCreate

func (c *Client) BeforeCreate() error

BeforeCreate a gorm callback

type DB

type DB struct {
	*gorm.DB
}

DB is an instant hold database connection

func NewDB

func NewDB() (*DB, error)

NewDB return a new MySQL connection

func (*DB) AllClients

func (db *DB) AllClients(clients *[]Client) []error

AllClients list all clients

func (*DB) AllUsers

func (db *DB) AllUsers(users *[]User) []error

AllUsers list all clients

func (*DB) GetClientsByUsername

func (db *DB) GetClientsByUsername(username string, clients *[]Client) []error

GetClientsByUsername get clients of an user by give username

func (*DB) GetUserByEmail

func (db *DB) GetUserByEmail(email string, user *User) []error

GetUserByEmail get user by give email

func (*DB) GetUserByUsername

func (db *DB) GetUserByUsername(username string, user *User) []error

GetUserByUsername get user by give username

type Datastore

type Datastore interface {
	AllUsers(*[]User) []error
	GetUserByUsername(string, *User) []error
	AllClients(*[]Client) []error
	GetClientsByUsername(string, *[]Client) []error
}

Datastore interface for easily mock up

type User

type User struct {
	gorm.Model
	FullName       string `gorm:"size:45"`
	Email          string `gorm:"type:varchar(100);unique_index"`
	Username       string `gorm:"type:varchar(25);unique_index"`
	Password       string `sql:"-"`
	HashedPassword string
	About          string
	Clients        []Client
}

User is a mqtt client model

func (*User) BeforeCreate

func (u *User) BeforeCreate() error

BeforeCreate a gorm callback

Jump to

Keyboard shortcuts

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