model

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACL

type ACL struct {
	AccessType    string `json:"accessType"`
	PrincipalType string `json:"principalType"`
}

type Config

type Config struct {
	Name       string              `json:"name"`
	Plural     string              `json:"plural"`
	Base       string              `json:"base"`
	Datasource string              `json:"dataSource"`
	Public     bool                `json:"public"`
	Properties map[string]Property `json:"properties"`
	Relations  map[string]Relation `json:"relations"`
	Acls       []ACL               `json:"acls"`
	Hidden     []string            `json:"hidden"`
}

type DataSourceConfig

type DataSourceConfig struct {
	Name      string `json:"name"`
	Connector string `json:"connector"`
	Host      string `json:"host"`
	Port      int    `json:"port"`
	Database  string `json:"database"`
	User      string `json:"user"`
	Password  string `json:"password"`
}

type EventContext

type EventContext struct {
	Data          *bson.M
	Instance      *ModelInstance
	Ctx           *fiber.Ctx
	IsNewInstance bool
	Result        interface{}
	ModelID       *primitive.ObjectID
	StatusCode    int
}

func (*EventContext) RestError

func (ctx *EventContext) RestError(fiberError *fiber.Error, details fiber.Map) error

type Model

type Model struct {
	Name       string `json:"name"`
	Config     Config
	Datasource *datasource.Datasource
	Router     *fiber.Router
	App        *common.IApp

	BaseUrl string
	// contains filtered or unexported fields
}

func New

func New(config Config) *Model

func (*Model) Build

func (loadedModel *Model) Build(data bson.M, fromDb bool) ModelInstance

func (*Model) Create

func (loadedModel *Model) Create(data interface{}) (*ModelInstance, error)

func (*Model) DeleteById

func (loadedModel *Model) DeleteById(id interface{}) (int64, error)

func (*Model) FindById

func (loadedModel *Model) FindById(id string, filterMap *map[string]interface{}) (*ModelInstance, error)

func (*Model) FindByIdRoute

func (loadedModel *Model) FindByIdRoute(c *fiber.Ctx) error

func (*Model) FindMany

func (loadedModel *Model) FindMany(filterMap *map[string]interface{}) ([]ModelInstance, error)

func (*Model) FindManyRoute

func (loadedModel *Model) FindManyRoute(c *fiber.Ctx) error

func (*Model) FindOne

func (loadedModel *Model) FindOne(filterMap *map[string]interface{}) (*ModelInstance, error)

func (*Model) GetHandler

func (loadedModel *Model) GetHandler(event string) func(eventContext *EventContext) error

func (*Model) Observe

func (loadedModel *Model) Observe(operation string, handler func(eventContext *EventContext) error)

func (*Model) On

func (loadedModel *Model) On(event string, handler func(eventContext *EventContext) error)

func (*Model) RemoteMethod

func (loadedModel *Model) RemoteMethod(handler func(c *fiber.Ctx) error, options RemoteMethodOptions) fiber.Router

func (*Model) SendError

func (loadedModel *Model) SendError(ctx *fiber.Ctx, err error) error

type ModelInstance

type ModelInstance struct {
	Model *Model
	Id    interface{}
	// contains filtered or unexported fields
}

func (ModelInstance) ToJSON

func (modelInstance ModelInstance) ToJSON() map[string]interface{}

func (ModelInstance) Transform

func (modelInstance ModelInstance) Transform(out interface{}) error

func (*ModelInstance) UpdateAttributes

func (modelInstance *ModelInstance) UpdateAttributes(data interface{}) (*ModelInstance, error)

type Property

type Property struct {
	Type     string `json:"type"`
	Required bool   `json:"required"`
	Default  string `json:"default"`
}

type RegistryEntry

type RegistryEntry struct {
	Name  string
	Model *Model
}

type Relation

type Relation struct {
	Type  string `json:"type"`
	Model string `json:"model"`
}

type RemoteMethodOptions

type RemoteMethodOptions struct {
	Description string
	Http        RemoteMethodOptionsHttp
}

type RemoteMethodOptionsHttp

type RemoteMethodOptionsHttp struct {
	Path string
	Verb string
}

type WeStackError

type WeStackError struct {
	FiberError *fiber.Error
	Details    fiber.Map
	Ctx        *EventContext
}

func (*WeStackError) Error

func (err *WeStackError) Error() string

Jump to

Keyboard shortcuts

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