Documentation ¶
Index ¶
- Variables
- func Count[T IObject](db IRelationalDB) int
- func DeepDelete[T IObject](db IRelationalDB, id string) error
- func Delete[T IObject](db IRelationalDB, id string) error
- func Encode(obj *IObject) []byte
- func Exist[T IObject](db IRelationalDB, id string) bool
- func Foreach[T IObject](db IRelationalDB, do func(id string, value *T))
- func MakeKey(tableName, id string) []byte
- func MakeLinkKey(tableName string, id string, targetName string, targetId string) []string
- func MakePrefix(tableName string) string
- func NameOfField(parent interface{}, field interface{}) (string, error)
- func NameOfStruct[T any]() string
- func ToString(v any) string
- func Type[T IObject]() *T
- type AbstractRelDB
- func (db *AbstractRelDB) CleanUnusedKey()
- func (db *AbstractRelDB) Count(prefix string) int
- func (db *AbstractRelDB) DeepDelete(tableName string, id string) error
- func (db *AbstractRelDB) Delete(tableName string, id string) error
- func (db *AbstractRelDB) FindAll(tableName string, predicate func(id string, value *IObject) bool) ([]string, []*IObject)
- func (db *AbstractRelDB) FindFirst(tableName string, predicate func(id string, value *IObject) bool) (string, *IObject)
- func (db *AbstractRelDB) Foreach(tableName string, do func(id string, value *IObject))
- func (db *AbstractRelDB) FreeKey(keys ...string) []error
- func (db *AbstractRelDB) Get(tableName string, id string) *IObject
- func (db *AbstractRelDB) GetNextKey() string
- func (db *AbstractRelDB) Insert(object IObject) string
- func (db *AbstractRelDB) Set(id string, object IObject) error
- func (db *AbstractRelDB) Update(tableName string, id string, editor func(value IObject) IObject) *IObject
- type DBObject
- type IObject
- type IRelationalDB
- type ObjWrapper
- func FindAll[T IObject](db IRelationalDB, predicate func(id string, value *T) bool) []*ObjWrapper[T]
- func FindFirst[T IObject](db IRelationalDB, predicate func(id string, value *T) bool) *ObjWrapper[T]
- func Get[T IObject](db IRelationalDB, id string) *ObjWrapper[T]
- func Insert[T IObject](db IRelationalDB, value T) *ObjWrapper[T]
- func NewObjWrapper[T IObject](db IRelationalDB, ID string, value *T) *ObjWrapper[T]
- func Set[T IObject](db IRelationalDB, id string, value T) *ObjWrapper[T]
- func Update[T IObject](db IRelationalDB, id string, editor func(value *T)) *ObjWrapper[T]
- func (t *ObjWrapper[IObject]) AllFromLink(tableName string) ([]string, []*IObject)
- func (t *ObjWrapper[IObject]) FromLink(tableName string) (string, *IObject)
- func (t *ObjWrapper[IObject]) Link(biDirectional bool, tableName string, ids ...string)
- func (t *ObjWrapper[IObject]) LinkNew(biDirectional bool, objs ...IObject) []*ObjWrapper[IObject]
Constants ¶
This section is empty.
Variables ¶
var ( AutoKeyBuffer = 100 PreAutoKavlb = "tank%avlb_" PreAutoKused = "tank%used_" PrefixLink = "link%" PrefixTable = "tbl%" Delimiter = "_" LinkDelimiter = "@" )
Functions ¶
func Count ¶
func Count[T IObject](db IRelationalDB) int
func DeepDelete ¶
func DeepDelete[T IObject](db IRelationalDB, id string) error
func Foreach ¶
func Foreach[T IObject](db IRelationalDB, do func(id string, value *T))
func MakeLinkKey ¶
func MakePrefix ¶
func NameOfField ¶
func NameOfStruct ¶
Types ¶
type AbstractRelDB ¶
type AbstractRelDB struct{ IRelationalDB }
AbstractRelDB pre-implement IRelationalDB, you need to set value of interface: methods implemented are used in abstract.
func (*AbstractRelDB) CleanUnusedKey ¶
func (db *AbstractRelDB) CleanUnusedKey()
func (*AbstractRelDB) Count ¶
func (db *AbstractRelDB) Count(prefix string) int
func (*AbstractRelDB) DeepDelete ¶
func (db *AbstractRelDB) DeepDelete(tableName string, id string) error
func (*AbstractRelDB) Foreach ¶
func (db *AbstractRelDB) Foreach(tableName string, do func(id string, value *IObject))
func (*AbstractRelDB) FreeKey ¶
func (db *AbstractRelDB) FreeKey(keys ...string) []error
func (*AbstractRelDB) GetNextKey ¶
func (db *AbstractRelDB) GetNextKey() string
func (*AbstractRelDB) Insert ¶
func (db *AbstractRelDB) Insert(object IObject) string
type IObject ¶
type IRelationalDB ¶
type IRelationalDB interface { // GetNextKey pick a key in tank of key. If tank is empty, it should be filled with unused key. GetNextKey() string // FreeKey check if key is used (return error otherwise) and make key available again. FreeKey(key ...string) []error CleanUnusedKey() // RawSet set a value in DB. prefix and key are simply concatenated. Don't care about Key is already in used or not. RawSet(prefix string, key string, value []byte) // RawGet get a value in DB. prefix and key are simply concatenated. If no value corresponding to this Key, //empty slice and false should be returned. RawGet(prefix string, key string) ([]byte, bool) // RawDelete delete a value in DB. prefix and key are simply concatenated. Return true if value is correctly deleted. RawDelete(prefix string, key string) bool // RawIterKey iterate in DB when prefix match with Key. //The action it called for each Key and the key is truncated with the prefix given. //The stop boolean defined if iteration should be stopped. No values are prefetched with this iterator. RawIterKey(prefix string, action func(key string) (stop bool)) // RawIterKV iterate in DB when prefix match with Key. //The action it called for each Key and the key is truncated with the prefix given. //The stop boolean defined if iteration should be stopped. value is the corresponding value of the key. RawIterKV(prefix string, action func(key string, value []byte) (stop bool)) // Insert create a new entry in storage with IObject passed. TableName is inferred with the IObject. Insert(object IObject) string // Set write a value for a specific id. TableName is inferred with the IObject. If Key not exist, an error is returned. Set(id string, object IObject) error // Get retrieve the value for corresponding TableName and ID. Return nil if nothing found. Get(tableName string, id string) *IObject // Update retrieve the value for corresponding TableName and ID, call the editor et Set the resulted value. Update(tableName string, id string, editor func(value IObject) IObject) *IObject // Delete remove the value for corresponding TableName and ID. If Key not exist, //an error is returned. The link using the object will be also deleted. Delete(tableName string, id string) error // DeepDelete remove the value for corresponding TableName and ID. If Key not exist, //an error is returned. It also recursively remove all values connected with a link. DeepDelete(tableName string, id string) error // Exist return true if the for corresponding TableName and ID exist in DB. Exist(tableName string, id string) bool // Count return the count for matching Key prefixed by TableName that exist in DB. Count(tableName string) int // Foreach call the do function for each value whose key is prefixed by TableName. Foreach(tableName string, do func(id string, value *IObject)) FindFirst(tableName string, predicate func(id string, value *IObject) bool) (string, *IObject) FindAll(tableName string, predicate func(id string, value *IObject) bool) ([]string, []*IObject) Print(tableName string) error }
IRelationalDB is a small interface to define some operation with a storage used like a relational DB.
Key ¶
In first, the underlying storage should be work like a KV DB. In consequence, a key is structured to store
- Key: internalTypePrefix, suffix
- Key for concrete type : internalTypePrefix, tableName, id
To make uniq key, a tank key system is implemented and can be used with GetNextKey, FreeKey. The global AutoKeyBuffer defined the size of this tank. When value is inserted, a key is pick in tank. When entry is deleted, the key become available again.
Operators ¶
All raw operator must be implemented ; other can be but are already implement in the abstraction AbstractRelDB. Raw Operators probably work directly with the db driver and are used by all other operators.
type ObjWrapper ¶
func FindAll ¶
func FindAll[T IObject](db IRelationalDB, predicate func(id string, value *T) bool) []*ObjWrapper[T]
func FindFirst ¶
func FindFirst[T IObject](db IRelationalDB, predicate func(id string, value *T) bool) *ObjWrapper[T]
func Get ¶
func Get[T IObject](db IRelationalDB, id string) *ObjWrapper[T]
func Insert ¶
func Insert[T IObject](db IRelationalDB, value T) *ObjWrapper[T]
func NewObjWrapper ¶
func NewObjWrapper[T IObject](db IRelationalDB, ID string, value *T) *ObjWrapper[T]
func Set ¶
func Set[T IObject](db IRelationalDB, id string, value T) *ObjWrapper[T]
func Update ¶
func Update[T IObject](db IRelationalDB, id string, editor func(value *T)) *ObjWrapper[T]
func (*ObjWrapper[IObject]) AllFromLink ¶
func (t *ObjWrapper[IObject]) AllFromLink(tableName string) ([]string, []*IObject)
func (*ObjWrapper[IObject]) FromLink ¶
func (t *ObjWrapper[IObject]) FromLink(tableName string) (string, *IObject)
func (*ObjWrapper[IObject]) Link ¶
func (t *ObjWrapper[IObject]) Link(biDirectional bool, tableName string, ids ...string)
func (*ObjWrapper[IObject]) LinkNew ¶
func (t *ObjWrapper[IObject]) LinkNew(biDirectional bool, objs ...IObject) []*ObjWrapper[IObject]