userfollow

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2017 License: MIT Imports: 7 Imported by: 0

README

Here is an example show how to use the gomodel package and cmd tool.

This example is about User-Follow, User can Follow and be Followed by other Users.

  • Main files:

    • db.go: DB and tables configurations
    • user.go: User structure
    • follow.go: Follow relationship structure
  • Other files:

    • model_gen.go: generated code for User and Follow
    • model.tmpl: template file for gmodel cmd's output
    • Makefile: automation
    • example_test.go: test cases

Documentation

Index

Constants

View Source
const (
	USER_ID uint64 = 1 << iota
	USER_NAME
	USER_AGE
	USER_FOLLOWINGS
	USER_FOLLOWERS

	UserTable         = "user"
	UserIdCol         = "id"
	UserNameCol       = "name"
	UserAgeCol        = "age"
	UserFollowingsCol = "followings"
	UserFollowersCol  = "followers"
)
View Source
const (
	FOLLOW_USERID uint64 = 1 << iota
	FOLLOW_FOLLOWUSERID

	FollowTable           = "user_follow"
	FollowUserIdCol       = "user_id"
	FollowFollowUserIdCol = "follow_user_id"
)

Variables

View Source
var (
	ErrFollowed  = httperrs.Conflict.NewS("already followed")
	ErrNonFollow = httperrs.NotFound.NewS("non follow")
)
View Source
var (
	ErrDuplicateUserName = httperrs.Conflict.NewS("user name already exists")
	ErrNoUser            = httperrs.NotFound.NewS("user not found")
)
View Source
var (
	DB = gomodel.NewDB()
)
View Source
var (
	FollowInstance = new(Follow)
)
View Source
var (
	UserInstance = new(User)
)

Functions

func DeleteUserById

func DeleteUserById(id int64) error

Types

type Follow

type Follow struct {
	UserId       int64 `table:"user_follow"`
	FollowUserId int64
}

func (*Follow) Add

func (f *Follow) Add() error

gomodel insertUserFollowSQL = [

INSERT INTO Follow(UserId, FollowUserId)
    SELECT ?, ? FROM DUAL
    WHERE EXISTS(SELECT Id FROM User WHERE Id=?)

]

func (*Follow) Columns

func (f *Follow) Columns() []string

func (*Follow) Delete

func (f *Follow) Delete() error

func (*Follow) Ptrs

func (f *Follow) Ptrs(fields uint64, ptrs []interface{})

func (*Follow) Table

func (f *Follow) Table() string

func (*Follow) Vals

func (f *Follow) Vals(fields uint64, vals []interface{})

type User

type User struct {
	Id   int64
	Name string
	Age  int

	Followings int
	Followers  int
}

func AllUsersByAge

func AllUsersByAge(age int) ([]User, error)

func UsersByAge

func UsersByAge(age, start, count int) ([]User, error)

func (*User) Add

func (u *User) Add() error

func (*User) ById

func (u *User) ById() error

func (*User) Columns

func (u *User) Columns() []string

func (*User) Ptrs

func (u *User) Ptrs(fields uint64, ptrs []interface{})

func (*User) Table

func (u *User) Table() string

func (*User) Update

func (u *User) Update() error

func (*User) Vals

func (u *User) Vals(fields uint64, vals []interface{})

Jump to

Keyboard shortcuts

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