mysql

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AclDSFactory

func AclDSFactory(acl ds.IDataSource) (ds.IAclDataSource, error)

UserDSFactory returns an object that implements user.IUserDataSource.

func Db

func Db() *sql.DB

Db returns the db handler

func Init

func Init() error

Init tests the db connection and saves the db handler

func PinDSFactory

func PinDSFactory(pin, user ds.IDataSource) (ds.IPinDataSource, error)

PinDSFactory returns an object that implements pin.IPinDataSource.

func UserDSFactory

func UserDSFactory(user ds.IDataSource) (ds.IUserDataSource, error)

UserDSFactory returns an object that implements user.IUserDataSource.

Types

type Dig

type Dig struct {
	Table   ITable
	Primary ds.Params
}

Dig exported

func NewDig

func NewDig(t ITable, p ds.Params) Dig

type ITable

type ITable interface {

	// ITable interfaces must fulfills ds.IDataSource
	ds.IDataSource

	// Dig offers a chance to optionally attach parent table data.
	// The included Table's Find and Fetch implementations of ITable calls Dig on each
	// found/fetched result, thus supporting nested digs. That is, it can go up in the relationship tree
	// digging parent data.
	//
	// f passes all parent relationships to dig. In a HTTP GET request, f are decoded from the
	// dig query params. ie.: https://my.site.com/clients?dig=clients.officer&dig=officers.location
	//
	// Implementation example:
	//
	// func (t *Client) Dig(f ...string) (dig []mysql.Dig) {
	//
	// 	 var p ds.Params
	//
	// 	 if lib.Contains(f, "clients.officer") && t.OfficerID != nil {
	// 		t.Officer = new(Officer)
	// 		p = make(ds.Params)
	// 		p["user_id"] = fmt.Sprint(*t.OfficerID)
	// 		dig = append(dig, mysql.NewDig(t.Officer, p))
	// 	 }
	//   return dig
	// }
	//
	// func (t *Officer) Dig(f ...string) (dig []mysql.Dig) {
	//
	// 	 var p ds.Params
	//
	// 	 if lib.Contains(f, "officers.location") {
	// 		t.Location = new(Location)
	// 		p = make(ds.Params)
	// 		p["location_id"] = fmt.Sprint(t.LocationID)
	// 		dig = append(dig, mysql.NewDig(t.Location, p))
	// 	 }
	//
	// 	 return dig
	// }
	Dig(f ...string) []Dig

	// BeforeSelect offers a chance optionally set additional constraints
	// in a per Table basis, or abort the select by returning a *ds.NotAllowedError.
	BeforeSelect(qo *ds.QueryOptions) (ds.Params, *ds.NotAllowedError)

	// BeforeInsert offers a chance to complete extra validations, alter values,
	// or abort the insert by returning an error.
	// Consider using *ds.NotAllowedError and/or validator.validationErrors, these
	// will be treated as such by ctrl.CrudController, others will be considered
	// InternalServerError's.
	BeforeInsert(qo *ds.QueryOptions) error

	// BeforeUpdate offers a chance to complete extra validations, alter values,
	// or abort the update by returning an error.
	// Consider using *ds.NotAllowedError and/or validator.validationErrors, these
	// will be treated as such by ctrl.CrudController, others will be considered
	// InternalServerError's.
	BeforeUpdate(qo *ds.QueryOptions) error

	// BeforeDelete offers a chance optionally set additional constraints
	// in a per Table basis, or even abort the select by returning a *ds.NotAllowedError.
	BeforeDelete(qo *ds.QueryOptions) (ds.Params, *ds.NotAllowedError)
}

ITable defines an interface for db table access. Consider annonymous embedding of Table in your concrete ITable. Table offers default implementation for all ITable and ds.IDataSource methods, except Name(). You can always overwrite the methods you need to. Check Table for more information.

type InsertError

type InsertError struct {
	msg.Message
}

InsertError exported

type NotITableError

type NotITableError struct {
	msg.Message
}

NotITableError exported

type Table

type Table struct{}

Table offers default implementation for all ITable and ds.IDataSource methods, except Name(). Consider annonymous embedding of Table in your concrete ITable.

func (Table) BeforeDelete

func (Table) BeforeDelete(qo *ds.QueryOptions) (ds.Params, *ds.NotAllowedError)

func (Table) BeforeInsert

func (Table) BeforeInsert(qo *ds.QueryOptions) error

func (Table) BeforeSelect

func (Table) BeforeSelect(qo *ds.QueryOptions) (ds.Params, *ds.NotAllowedError)

func (Table) BeforeUpdate added in v0.2.10

func (Table) BeforeUpdate(qo *ds.QueryOptions) error

func (Table) Count added in v0.2.11

func (Table) Count(qo *ds.QueryOptions) (count int64, err error)

Count returns the number of qo.DataSource records that match qo settings. Beware that qo.DataSource must implement ITable.

func (Table) Delete

func (Table) Delete(qo *ds.QueryOptions) (int64, error)

Delete supports single and multiple records removal. It first checks with Table's BeforeDelete method for extra constraints. BeforeDelete can also return a *ds.NotAllowedError to abort Delete. Beware that qo.DataSource must implement ITable.

func (Table) Dig

func (Table) Dig(f ...string) []Dig

func (Table) Fetch

func (Table) Fetch(qo *ds.QueryOptions) (meta ds.ResultSetMeta, data []interface{}, err error)

Fetch returns the qo.DataSource records that match qo settings. Supports BeforeSelect(qo) and parent data retrieval through dig params. If a parent resource is not found, Fetch is aborted with a NotFoundError. Beware that qo.DataSource must implement ITable.

func (Table) Find

func (Table) Find(qo *ds.QueryOptions) (meta ds.ResultSetMeta, data interface{}, err error)

Find returns the qo.DataSource record that matches qo settings. Supports BeforeSelect(qo) and parent data retrieval through dig params. If a parent resource is not found, Find is aborted with a NotFoundError. Beware that qo.DataSource must implement ITable.

func (Table) Insert

func (Table) Insert(qo *ds.QueryOptions) error

Insert exported

func (Table) Update added in v0.2.11

func (Table) Update(qo *ds.QueryOptions) (int64, error)

Update exported

type UpdateError

type UpdateError struct {
	msg.Message
}

UpdateError exported

Jump to

Keyboard shortcuts

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