models

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	Id         int32            `db:"id"`
	Uid        int32            `db:"uid"`
	Name       string           `db:"name"`
	Content    typex.NullString `db:"content"`
	CreateTime typex.NullTime   `db:"create_time"`
	Price      int32            `db:"price"`
}

Type definition for Book which defined in sql file. This can be used as a model in database operation.

type BookBrick

type BookBrick struct {
	// contains filtered or unexported fields
}

Type definition for BookBrick. This brick will contains all database operation from given sql file. Each sql file will have only one brick.

func (*BookBrick) AddOne added in v0.2.0

func (b *BookBrick) AddOne(args *Book) (sql.Result, error)

AddOne generated by sqlbrick, insert data into database.

func (*BookBrick) ComplexUpdate

func (b *BookBrick) ComplexUpdate(args *Book) (int64, error)

ComplexUpdate an example to show complex update. Second line comment.

func (*BookBrick) CountBooks

func (b *BookBrick) CountBooks(dest interface{}, uid interface{}) error

CountBooks generated by sqlbrick, select data from database.

func (*BookBrick) CreateBook

func (b *BookBrick) CreateBook() error

CreateBook create table if not exsited

func (*BookBrick) DeleteById

func (b *BookBrick) DeleteById(id interface{}) (int64, error)

DeleteById an example to show DeleteById.

func (*BookBrick) DeleteByIdAndUid added in v0.2.0

func (b *BookBrick) DeleteByIdAndUid(args interface{}) (int64, error)

DeleteByIdAndUid generated by sqlbrick, delete data from database. Affected rows will return if there's no error.

func (*BookBrick) SelectAll

func (b *BookBrick) SelectAll(dest interface{}) error

SelectAll generated by sqlbrick, select data from database.

func (*BookBrick) SelectById

func (b *BookBrick) SelectById(dest interface{}, id interface{}) error

SelectById an example to show SelectById.

func (*BookBrick) SelectByUid

func (b *BookBrick) SelectByUid(dest interface{}, uid interface{}) error

SelectByUid generated by sqlbrick, select data from database.

func (*BookBrick) UpdateSomeThing

func (b *BookBrick) UpdateSomeThing(args *Book) (int64, error)

UpdateSomeThing an example to show update.

type BookBrickTx

type BookBrickTx struct {
	// contains filtered or unexported fields
}

Type definition for Book transaction. This aims at sql transaction.

func (*BookBrickTx) TxDeleteById

func (b *BookBrickTx) TxDeleteById(id interface{}) (int64, error)

TxDeleteById generated by sqlbrick, delete data from database. Affected rows will return if there's no error.

func (*BookBrickTx) TxInsert

func (b *BookBrickTx) TxInsert(args *Book) (sql.Result, error)

TxInsert generated by sqlbrick, insert data into database.

func (*BookBrickTx) TxSelect

func (b *BookBrickTx) TxSelect(dest interface{}, uid interface{}) error

TxSelect generated by sqlbrick, select data from database.

func (*BookBrickTx) TxUpdate

func (b *BookBrickTx) TxUpdate(args *Book) (int64, error)

TxUpdate generated by sqlbrick, update data in database.

type BrickTx

type BrickTx struct {
	Book *BookBrickTx
	User *UserBrickTx
	// contains filtered or unexported fields
}

Type definition for brick transaction. This aims at sql transaction. If you want a transaction, then invoke 'Begin' to get this struct.

func (*BrickTx) Commit

func (b *BrickTx) Commit() error

Commit will end a transaction for brick. Begin must be invoked before Commit. Otherwise there will be an error.

type SqlBrick

type SqlBrick struct {
	Db   *sqlx.DB
	Book *BookBrick
	User *UserBrick
}

Type definition for SqlBrick. It contains all bricks depend on the number of sql files. It also wraps some sqlx func for for convenience.

func NewSqlBrick

func NewSqlBrick(db *sqlx.DB) *SqlBrick

NewSqlBrick create a new SqlBrick to operate all bricks.

func (*SqlBrick) Begin

func (b *SqlBrick) Begin() (*BrickTx, error)

Begin will start a new transaction for bricks. If any query is defined as tx sql, this must be invoked.

type User

type User struct {
	Id   int32  `db:"id"`
	Name string `db:"name"`
	Age  int32  `db:"age"`
}

Type definition for User which defined in sql file. This can be used as a model in database operation.

type UserBrick

type UserBrick struct {
	// contains filtered or unexported fields
}

Type definition for UserBrick. This brick will contains all database operation from given sql file. Each sql file will have only one brick.

func (*UserBrick) CountAll

func (b *UserBrick) CountAll(dest interface{}) error

CountAll generated by sqlbrick, select data from database.

func (*UserBrick) CreateUser

func (b *UserBrick) CreateUser() error

CreateUser generated by sqlbrick, used to operate database table.

func (*UserBrick) SelectById

func (b *UserBrick) SelectById(dest interface{}, id interface{}) error

SelectById name: SelectById

func (*UserBrick) UnionSelect added in v0.2.0

func (b *UserBrick) UnionSelect(dest interface{}) error

UnionSelect generated by sqlbrick, select data from database.

type UserBrickTx

type UserBrickTx struct {
	// contains filtered or unexported fields
}

Type definition for User transaction. This aims at sql transaction.

func (*UserBrickTx) TxDelete

func (b *UserBrickTx) TxDelete(id interface{}) (int64, error)

TxDelete generated by sqlbrick, delete data from database. Affected rows will return if there's no error.

func (*UserBrickTx) TxInsert

func (b *UserBrickTx) TxInsert(args *User) (sql.Result, error)

TxInsert generated by sqlbrick, insert data into database.

Jump to

Keyboard shortcuts

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