model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// EnableSQLite3 for enable sqlite 3
	EnableSQLite3 bool
)

Functions

func AssertCount

func AssertCount(t testing.TB, bean interface{}, expected interface{})

AssertCount assert the count of a bean

func AssertExistsAndLoadBean

func AssertExistsAndLoadBean(t testing.TB, bean interface{}, conditions ...interface{}) interface{}

AssertExistsAndLoadBean assert that a bean exists and load it from the test database

func AssertExistsIf

func AssertExistsIf(t *testing.T, expected bool, bean interface{}, conditions ...interface{})

AssertExistsIf asserts that a bean exists or does not exist, depending on what is expected.

func AssertInt64InRange

func AssertInt64InRange(t testing.TB, low, high, value int64)

AssertInt64InRange assert value is in range [low, high]

func AssertNotExistsBean

func AssertNotExistsBean(t testing.TB, bean interface{}, conditions ...interface{})

AssertNotExistsBean assert that a bean does not exist in the test database

func AssertSuccessfulInsert

func AssertSuccessfulInsert(t testing.TB, beans ...interface{})

AssertSuccessfulInsert assert that beans is successfully inserted

func BeanExists

func BeanExists(t testing.TB, bean interface{}, conditions ...interface{}) bool

BeanExists for testing, check if a bean exists

func Cond

func Cond(query interface{}, args ...interface{}) interface{}

Cond create a condition with arguments for a test

func CreateUser

func CreateUser(u *User) (err error)

CreateUser creates record of a new user.

func DeleteAccessTokenByID

func DeleteAccessTokenByID(id, userID int64) error

DeleteAccessTokenByID deletes access token by given ID.

func GetCount

func GetCount(t testing.TB, bean interface{}, conditions ...interface{}) int

GetCount get the count of a bean

func InitFixtures

func InitFixtures(helper testfixtures.Helper, dir string) (err error)

InitFixtures initialize test fixtures for a test database

func IsErrAccessTokenEmpty

func IsErrAccessTokenEmpty(err error) bool

IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.

func IsErrAccessTokenNotExist

func IsErrAccessTokenNotExist(err error) bool

IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.

func IsErrEmailAlreadyUsed

func IsErrEmailAlreadyUsed(err error) bool

IsErrEmailAlreadyUsed checks if an error is a ErrEmailAlreadyUsed.

func IsErrShortenNotExist

func IsErrShortenNotExist(err error) bool

IsErrShortenNotExist checks if an error is a ErrUserNotExist.

func IsErrURLExist

func IsErrURLExist(err error) bool

IsErrURLExist checks if an error is a ErrURLExist.

func IsErrUserAlreadyExist

func IsErrUserAlreadyExist(err error) bool

IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.

func IsErrUserNotExist

func IsErrUserNotExist(err error) bool

IsErrUserNotExist checks if an error is a ErrUserNotExist.

func IsUserExist

func IsUserExist(uid int64, email string) (bool, error)

IsUserExist checks if given user email exist, the user email should be noncased unique. If uid is presented, then check will rule out that one, it is used when update a user email in settings page.

func LoadFixtures

func LoadFixtures() error

LoadFixtures load fixtures for a test database

func MainTest

func MainTest(m *testing.M, pathToRoot string)

MainTest a reusable TestMain(..) function for unit tests that need to use a test database. Creates the test database, and sets necessary settings.

func NewAccessToken

func NewAccessToken(t *AccessToken) error

NewAccessToken creates new access token.

func NewEngine

func NewEngine() (err error)

NewEngine initializes a new xorm.Engine

func PrepareTestDatabase

func PrepareTestDatabase() error

PrepareTestDatabase load test fixtures into test database

func PrepareTestEnv

func PrepareTestEnv(t testing.TB)

PrepareTestEnv prepares the environment for unit tests. Can only be called by tests that use the above MainTest(..) function.

func SetEngine

func SetEngine() (err error)

SetEngine sets the xorm.Engine

func UpdateAccessToken

func UpdateAccessToken(t *AccessToken) error

UpdateAccessToken updates information of access token.

func UpdateUser

func UpdateUser(u *User) error

UpdateUser updates user's information.

func UpdateUserCols

func UpdateUserCols(u *User, cols ...string) error

UpdateUserCols update user according special columns

Types

type AccessToken

type AccessToken struct {
	ID     int64 `xorm:"pk autoincr"`
	UserID int64 `xorm:"INDEX"`
	Name   string
	Sha1   string `xorm:"UNIQUE VARCHAR(40)"`

	CreatedAt         time.Time `xorm:"created" json:"created_at,omitempty"`
	UpdatedAt         time.Time `xorm:"updated" json:"updated_at,omitempty"`
	HasRecentActivity bool      `xorm:"-"`
	HasUsed           bool      `xorm:"-"`
}

AccessToken represents a personal access token.

func GetAccessTokenBySHA

func GetAccessTokenBySHA(sha string) (*AccessToken, error)

GetAccessTokenBySHA returns access token by given sha1.

func (*AccessToken) AfterLoad

func (t *AccessToken) AfterLoad()

AfterLoad is invoked from XORM after setting the values of all fields of this object.

type Engine

type Engine interface {
	Table(tableNameOrBean interface{}) *xorm.Session
	Count(...interface{}) (int64, error)
	Decr(column string, arg ...interface{}) *xorm.Session
	Delete(interface{}) (int64, error)
	Exec(...interface{}) (sql.Result, error)
	Find(interface{}, ...interface{}) error
	Get(interface{}) (bool, error)
	ID(interface{}) *xorm.Session
	In(string, ...interface{}) *xorm.Session
	Incr(column string, arg ...interface{}) *xorm.Session
	Insert(...interface{}) (int64, error)
	InsertOne(interface{}) (int64, error)
	Iterate(interface{}, xorm.IterFunc) error
	Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *xorm.Session
	SQL(interface{}, ...interface{}) *xorm.Session
	Where(interface{}, ...interface{}) *xorm.Session
}

Engine represents a xorm engine or session.

type ErrAccessTokenEmpty

type ErrAccessTokenEmpty struct {
}

ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.

func (ErrAccessTokenEmpty) Error

func (err ErrAccessTokenEmpty) Error() string

type ErrAccessTokenNotExist

type ErrAccessTokenNotExist struct {
	SHA string
}

ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.

func (ErrAccessTokenNotExist) Error

func (err ErrAccessTokenNotExist) Error() string

type ErrEmailAlreadyUsed

type ErrEmailAlreadyUsed struct {
	Email string
}

ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.

func (ErrEmailAlreadyUsed) Error

func (err ErrEmailAlreadyUsed) Error() string

type ErrShortenNotExist

type ErrShortenNotExist struct {
	Slug string
}

ErrShortenNotExist represents a "ShortenNotExist" kind of error.

func (ErrShortenNotExist) Error

func (err ErrShortenNotExist) Error() string

type ErrURLExist

type ErrURLExist struct {
	Slug string
	URL  string
}

ErrURLExist represents a "ErrURLExist" kind of error.

func (ErrURLExist) Error

func (err ErrURLExist) Error() string

type ErrUserAlreadyExist

type ErrUserAlreadyExist struct {
	Name string
}

ErrUserAlreadyExist represents a "user already exists" error.

func (ErrUserAlreadyExist) Error

func (err ErrUserAlreadyExist) Error() string

type ErrUserNotExist

type ErrUserNotExist struct {
	UID   int64
	Name  string
	KeyID int64
}

ErrUserNotExist represents a "UserNotExist" kind of error.

func (ErrUserNotExist) Error

func (err ErrUserNotExist) Error() string

type Shorten

type Shorten struct {
	Slug        string    `xorm:"pk VARCHAR(14)" json:"slug"`
	UserID      int64     `xorm:"INDEX" json:"-"`
	URL         string    `xorm:"NOT NULL VARCHAR(620)" json:"url"`
	Date        time.Time `json:"date"`
	Hits        int64     `xorm:"NOT NULL DEFAULT 0" json:"hits"`
	Title       string    `xorm:"VARCHAR(512)" json:"title"`
	Description string    `xorm:"TEXT" json:"description"`
	Type        string    `json:"type"`
	Image       string    `json:"image"`
	CreatedAt   time.Time `xorm:"created" json:"created_at,omitempty"`
	UpdatedAt   time.Time `xorm:"updated" json:"updated_at,omitempty"`

	// reference
	User *User `xorm:"-" json:"user"`
}

Shorten shortener URL

func CreateShorten

func CreateShorten(url string, size int, user *User) (_ *Shorten, err error)

CreateShorten create url item

func GetShortenBySlug

func GetShortenBySlug(slug string) (*Shorten, error)

GetShortenBySlug returns the shorten object by given slug if exists.

func GetShortenFromURL

func GetShortenFromURL(url string) (*Shorten, error)

GetShortenFromURL check url exist

func GetShortenURLs

func GetShortenURLs(userID int64, page, pageSize int, orderBy string) ([]*Shorten, error)

GetShortenURLs returns a list of urls of given user.

func (*Shorten) GetUser

func (s *Shorten) GetUser() error

GetUser returns the shorten owner

func (*Shorten) UpdateHits

func (s *Shorten) UpdateHits(slug string) error

UpdateHits udpate hit count

func (*Shorten) UpdateMetaData

func (s *Shorten) UpdateMetaData() error

UpdateMetaData form raw body

type User

type User struct {
	ID       int64  `xorm:"pk autoincr" json:"id,omitempty"`
	FullName string `json:"fullname,omitempty"`
	// Email is the primary email address (to be used for communication)
	Email       string `xorm:"UNIQUE NOT NULL" json:"email,omitempty"`
	Location    string
	Website     string
	IsActive    bool      `xorm:"INDEX"` // Activate primary email
	Avatar      string    `xorm:"VARCHAR(2048) NOT NULL" json:"avatar,omitempty"`
	AvatarEmail string    `xorm:"NOT NULL" json:"avatar_email,omitempty"`
	CreatedAt   time.Time `xorm:"created" json:"created_at,omitempty"`
	UpdatedAt   time.Time `xorm:"updated" json:"updated_at,omitempty"`
	LastLogin   time.Time `json:"lastlogin,omitempty"`
}

User represents the object of individual and member of organization.

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail returns the user object by given e-mail if exists.

func GetUserByID

func GetUserByID(id int64) (*User, error)

GetUserByID returns the user object by given ID if exists.

func (*User) BeforeInsert

func (u *User) BeforeInsert()

BeforeInsert will be invoked by XORM before inserting a record

func (*User) BeforeUpdate

func (u *User) BeforeUpdate()

BeforeUpdate is invoked from XORM before updating this object.

Jump to

Keyboard shortcuts

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