micro/model/model.go
Vasiliy Tolstov 06136312bb
regen files with never protoc (#6)
* regen files with never protoc
* rewrite import path

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-08-19 17:47:17 +03:00

61 lines
1.3 KiB
Go

// Package model is an interface for data modelling
package model
import (
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/store"
"github.com/unistack-org/micro/v3/sync"
)
// Model provides an interface for data modelling
type Model interface {
// Initialise options
Init(...Option) error
// NewEntity creates a new entity to store or access
NewEntity(name string, value interface{}) Entity
// Create a value
Create(Entity) error
// Read values
Read(...ReadOption) ([]Entity, error)
// Update the value
Update(Entity) error
// Delete an entity
Delete(...DeleteOption) error
// Implementation of the model
String() string
}
type Entity interface {
// Unique id of the entity
Id() string
// Name of the entity
Name() string
// The value associated with the entity
Value() interface{}
// Attributes of the entity
Attributes() map[string]interface{}
// Read a value as a concrete type
Read(v interface{}) error
}
type Options struct {
// Database to write to
Database string
// for serialising
Codec codec.Marshaler
// for locking
Sync sync.Sync
// for storage
Store store.Store
}
type Option func(o *Options)
type ReadOptions struct{}
type ReadOption func(o *ReadOptions)
type DeleteOptions struct{}
type DeleteOption func(o *DeleteOptions)