Documentation ¶
Index ¶
- Variables
- type CRUD
- func (c *CRUD) Begin() (*CRUDTx, error)
- func (c *CRUD) BeginTx(ctx context.Context, opts *sql.TxOptions) (*CRUDTx, error)
- func (c *CRUD) Delete(table string, data interface{}) (sql.Result, error)
- func (c *CRUD) DeleteContext(ctx context.Context, table string, data interface{}) (sql.Result, error)
- func (c *CRUD) Insert(table string, data interface{}) (sql.Result, error)
- func (c *CRUD) InsertContext(ctx context.Context, table string, data interface{}) (sql.Result, error)
- func (c *CRUD) Select(holder interface{}, query string, args ...interface{}) error
- func (c *CRUD) SelectContext(ctx context.Context, holder interface{}, query string, args ...interface{}) error
- func (c *CRUD) Update(table string, data interface{}) (sql.Result, error)
- func (c *CRUD) UpdateContext(ctx context.Context, table string, data interface{}) (sql.Result, error)
- type CRUDTx
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPkField = errors.New("crud: struct with invalid pk field")
ErrInvalidPkField means that provided struct do not have field with `db:",pk"` tag
var ErrNotAStruct = errors.New("crud: data not a struct")
ErrNotAStruct means that provided data is not a struct and insert cannot be performed
var ErrTooManyColumns = errors.New("crud: too many columns")
ErrTooManyColumns means that provided query in Select function returned more columns that holder can hold
var ErrTooManyRows = errors.New("crud: too many rows")
ErrTooManyRows means that provided query in Select function returned more rows that holder can hold usually that means that holder is not a slice or lacking a LIMIT in query
Functions ¶
This section is empty.
Types ¶
type CRUD ¶
func (*CRUD) BeginTx ¶
BeginTx creates new transaction with given context and TxOptions wrapped with CRUDTx struct
func (*CRUD) Delete ¶
Delete created and performs DELETE FROM table WHERE ... LIMIT 1 If data parameter is not a struct ErrNotAStruct will be returned If data do not have field with `db:",pk"` tag ErrInvalidPkField will be returned
func (*CRUD) DeleteContext ¶
func (c *CRUD) DeleteContext(ctx context.Context, table string, data interface{}) (sql.Result, error)
DeleteContext created and performs DELETE FROM table WHERE ... LIMIT 1 with a given context If data parameter is not a struct ErrNotAStruct will be returned If data do not have field with `db:",pk"` tag ErrInvalidPkField will be returned
func (*CRUD) Insert ¶
Insert created and performs INSERT INTO ... query If data parameter is not a struct ErrNotAStruct will be returned
func (*CRUD) InsertContext ¶
func (c *CRUD) InsertContext(ctx context.Context, table string, data interface{}) (sql.Result, error)
InsertContext created and performs INSERT INTO ... query with a given context If data parameter is not a struct ErrNotAStruct will be returned
func (*CRUD) Select ¶
Select is used for performing `SELECT` query and unpacking the result into `holder` Holder can be any type (byte, int, string, bool, struct) and slice of any type If holder is not a slice and query returns more than one row ErrTooManyRows will be returned If holder is byte, int, string or bool and query returns a more than one column ErrTooManyColumns will be returned
func (*CRUD) SelectContext ¶
func (c *CRUD) SelectContext(ctx context.Context, holder interface{}, query string, args ...interface{}) error
SelectContext is used for performing `SELECT` query and unpacking the result into `holder` Holder can be any type (byte, int, string, bool, struct) and slice of any type If holder is not a slice and query returns more than one row ErrTooManyRows will be returned If holder is byte, int, string or bool and query returns a more than one column ErrTooManyColumns will be returned
func (*CRUD) Update ¶
Update create and performs UPDATE table SET ... WHERE `pk` = ? query If data parameter is not a struct ErrNotAStruct will be returned If data do not have field with `db:",pk"` tag ErrInvalidPkField will be returned
func (*CRUD) UpdateContext ¶
func (c *CRUD) UpdateContext(ctx context.Context, table string, data interface{}) (sql.Result, error)
UpdateContext create and performs UPDATE table SET ... WHERE `pk` = ? LIMIT 1 query with a given context If data parameter is not a struct ErrNotAStruct will be returned If data do not have field with `db:",pk"` tag ErrInvalidPkField will be returned