From ee36e26edcc8499d8452d36184d3a434a160c5bd Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Jul 2020 14:57:45 +0100 Subject: [PATCH] Add model interface (#1808) --- model/model.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 model/model.go diff --git a/model/model.go b/model/model.go new file mode 100644 index 00000000..b0684ef3 --- /dev/null +++ b/model/model.go @@ -0,0 +1,51 @@ +// Package model is an interface for data modelling +package model + +import ( + "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 + // The value associated with the entity + Value() interface{} + // Attributes of the enity + Attributes() map[string]interface{} +} + +type Options struct { + // 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)