liborm

package
v0.0.0-...-fda232b Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cluster *libdata.Cluster
View Source
var Validate *validator.Validate

Validate todo

Functions

func GetIdsFromRecordList

func GetIdsFromRecordList(records []libdata.ModelInterface) []string

GetIdsFromRecordList will return the uuid from a list of records.

Types

type Collection

type Collection struct {
	Definition *Definition
	Env        *Env

	Update  func(interface{}, *fieldmask.FieldMask) error
	Delete  func() error
	NewPool func() *Pool
	// contains filtered or unexported fields
}

Collection contains several objects of a same model.

func (*Collection) GetByUUID

func (c *Collection) GetByUUID(uuid string) interface{}

GetByUUID will return the specified record in the collection, by UUID.

func (*Collection) Init

func (c *Collection) Init(records []libdata.ModelInterface)

Init will initialize the collection with the specified records.

func (*Collection) Slice

func (c *Collection) Slice() []libdata.ModelInterface

Slice will return the records in the collection, as a slice.

type CustomFunc

type CustomFunc struct {
	Name    string
	Args    []libdata.Field
	Results []libdata.Field
}

CustomFunc represent a custom function.

func (*CustomFunc) Title

func (f *CustomFunc) Title() string

type Definition

type Definition struct {
	Model                 *libdata.ModelDefinition
	Tree                  bool
	TranslamodelFields    []string
	TranslateModel        *Definition
	CustomFuncsPool       []*CustomFunc
	CustomFuncsCollection []*CustomFunc
	// contains filtered or unexported fields
}

Definition is used to declare the information of a model, so it can generate its code.

var DataModel *Definition

DataModel is a special definition to import data into the service.

func (*Definition) SetNew

func (d *Definition) SetNew(new func() interface{}) error

SetNew is used to set the new function.

func (*Definition) SetStore

func (d *Definition) SetStore(store interface{}) error

SetStore is used to set the store of the model.

type Definitions

type Definitions struct {
	Repository string
	// contains filtered or unexported fields
}

func (*Definitions) Gen

func (defs *Definitions) Gen()

Gen will generate the models files.

func (*Definitions) GenProtos

func (defs *Definitions) GenProtos()

GenProtos will generate the protobuf files for the models.

func (*Definitions) GetByID

func (ds *Definitions) GetByID(id string) *Definition

GetByID return the specified definition by its ID.

func (*Definitions) Register

func (ds *Definitions) Register(d *Definition)

Register is used to register a new definition into the service.

func (*Definitions) Slice

func (ds *Definitions) Slice() []*Definition

Slice return the definitions as a slice.

type Env

type Env struct {
	Context     context.Context
	Transaction *libdata.Transaction
}

Env contain the context in which the current transaction is occurring.

type Model

type Model struct{}

Model represent a single record.

type ModelInterface

type ModelInterface interface {
	Select(
		context.Context, *libdata.Transaction, []*libdata.Filter,
		[]string, *uint, *string, *string,
	) (*Collection, error)
	Create(context.Context, *libdata.Transaction, []interface{}) (*Collection, error)
	Delete(
		context.Context, *libdata.Transaction, []*libdata.Filter, []string,
	) (*Collection, error)
	SetStore(interface{}) error
	SetNew(func() interface{}) error
}

ModelInterface force to define the function relative to Model.

type Pool

type Pool struct {
	Definition               *Definition
	Env                      *Env
	New                      func() libdata.ModelInterface
	Scan                     func(interface{}, *Collection) ([]libdata.ModelInterface, error)
	CheckExternalForeignKeys func([]libdata.ModelInterface) error
	Select                   func(
		filters []*libdata.Filter, with []string,
		limit *uint, after *string, orderByArg *string,
	) (*Collection, error)
	Create     func(records []libdata.ModelInterface) (*Collection, error)
	PostCreate func(records *Collection) error
	Upsert     func([]*libdata.Filter, interface{}, bool) (interface{}, bool, error)
}

Pool represent a Model within the current environnement, so we can easily make operation on it.

func (*Pool) Init

func (d *Pool) Init()

Init will initialize the pool.

Jump to

Keyboard shortcuts

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