db

package
v0.1.40 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByID added in v0.1.37

func ByID(tbl Table, idv ...string) error

ByID exported

func Db

func Db() *sql.DB

Db returns the db handler

func FindOptionsFactory added in v0.1.39

func FindOptionsFactory(tbl Table, uid string, param url.Values, idv []string) (*FindOptions, *ParamError)

FindOptionsFactory exported

func Init

func Init() error

Init tests the db connection and saves the db handler

func Pk added in v0.1.35

func Pk(tbl Table) (f []string)

Returns a slice of db fields tagged as `pk:"1"`

func TaggedFields added in v0.1.35

func TaggedFields(tbl Table, tagName string, tagValues []string) ([]string, error)

TaggedFields returns a slice of db fields sharing a tag name (tn) such fields must be tagged as tn:"tv" the tagName value is passed in the tn parameter tagValues options are passed in the tv parameter ie.:

type User struct {
	 UserID    int64     `db:"user_id"   auth:"id"    json:"user_id"   pk:"1"`
	 RoleID    *int64    `db:"role_id"   auth:"role"  json:"role_id"`
	 Email     string    `db:"email"     auth:"usr"   json:"email"`
}

v ar m User f, _ := TaggedFields(m, "auth", []string{"id","role","usr"}) f -> []string{"user_id","role_id","email"}

Types

type BaseTable added in v0.1.35

type BaseTable struct{}

func (BaseTable) Dig added in v0.1.35

func (BaseTable) Dig()

Dig exported

func (BaseTable) Scope added in v0.1.35

func (BaseTable) Scope(uid string, t ...Table) map[string]string

Scope exported

type ConflictError added in v0.1.35

type ConflictError struct {
	msg.Message
}

ConflictError exported

type FetchOptions added in v0.1.36

type FetchOptions struct {
	Table            Table
	UID              string  // ID from jwt, used to set scope in find, fetch, etc.
	Parents          []Table // Also used to set scope in find, fetch, etc.
	Column           []string
	IsNull           []string
	IsNotNull        []string
	In               map[string][]interface{}
	NotIn            map[string][]interface{}
	Equal            map[string]string
	NotEqual         map[string]string
	GreaterThan      map[string]string
	LessThan         map[string]string
	GreaterEqualThan map[string]string
	LessEqualThan    map[string]string
	Order            []string
	Offset           int
	Limit            int
	Checksum         int
	Dig              int // Flag used to include (or not) parent data in find, fetch, etc.
}

FetchOptions exported

func FetchOptionsFactory added in v0.1.39

func FetchOptionsFactory(tbl Table, uid string, param url.Values, parents ...Table) *FetchOptions

FetchOptionsFactory exported

type FetchResultSetMeta added in v0.1.39

type FetchResultSetMeta struct {
	Range    string
	Checksum string
}

FetchResultSetMeta exported

func Fetch added in v0.1.36

func Fetch(fo *FetchOptions) (FetchResultSetMeta, []interface{}, error)

Fetch exported

type FindOptions added in v0.1.39

type FindOptions struct {
	Table    Table
	Where    map[string]string
	Checksum int
	Dig      int
	UID      string
}

FindOptions exported

type FindResultSetMeta added in v0.1.39

type FindResultSetMeta struct {
	Checksum string
}

FindResultSetMeta exported

func Find added in v0.1.35

func Find(fo *FindOptions) (FindResultSetMeta, interface{}, error)

Find exported

type NotAllowedError added in v0.1.35

type NotAllowedError struct {
	msg.Message
}

NotAllowedError exported

type NotFoundError added in v0.1.35

type NotFoundError struct {
	msg.Message
}

NotFoundError exported

type ParamError added in v0.1.35

type ParamError struct {
	msg.Message
}

ParamError exported

type Table added in v0.1.33

type Table interface {

	// Must return the table name
	Name() string

	// Must attach foreign table data if available
	Dig()

	// Must set conditions to filter out content
	// not intended for the user making the request
	Scope(uid string, t ...Table) map[string]string
}

Table exported

type TableMeta added in v0.1.36

type TableMeta struct {
	Fields   []string
	Primary  []string
	Serial   []string
	View     []string
	Writable []string
}

TableMeta exported

func GetTableMeta added in v0.1.36

func GetTableMeta(tbl Table) (meta TableMeta)

Returns the TableMeta object for tbl param. The underlying tbl struct must be properly annotated with Table related tags. TableMeta supports the tags: db, pk, view, serial.

Jump to

Keyboard shortcuts

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