2020-07-08 16:57:45 +03:00
|
|
|
// Package model is an interface for data modelling
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2020-07-08 17:09:18 +03:00
|
|
|
"github.com/micro/go-micro/v2/codec"
|
2020-07-08 16:57:45 +03:00
|
|
|
"github.com/micro/go-micro/v2/store"
|
|
|
|
"github.com/micro/go-micro/v2/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
|
2020-07-08 17:09:18 +03:00
|
|
|
// Name of the entity
|
|
|
|
Name() string
|
2020-07-08 16:57:45 +03:00
|
|
|
// The value associated with the entity
|
|
|
|
Value() interface{}
|
|
|
|
// Attributes of the enity
|
|
|
|
Attributes() map[string]interface{}
|
2020-07-08 17:09:18 +03:00
|
|
|
// Read a value as a concrete type
|
|
|
|
Read(v interface{}) error
|
2020-07-08 16:57:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Options struct {
|
2020-07-08 17:09:18 +03:00
|
|
|
// for serialising
|
|
|
|
Codec codec.Marshaler
|
2020-07-08 16:57:45 +03:00
|
|
|
// 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)
|