shdb

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

README

Shdb

A simple database for protobuf based objects

Installing

$ go get github.com/shenrytech/shdb

Example

package main

func main() {
	Init(path.Join(os.TempDir(), "example_query.db"))
	Register(&TObject{
		Metadata: &Metadata{Type: TObj[:]},
		MyString:  "The flying duck is flying low"})

	count := 100
	pageSize := 10

	list := []*TObject{}
	for k := 0; k < count; k++ {
		tObj := MustNew[*TObject](TObj)
		tObj.MyInt = uint64(k)
		list = append(list, tObj)
	}
	if err := Put(list...); err != nil {
		panic(err)
	}

	defer func() {
		Close()
		os.Remove(path.Join(os.TempDir(), "example_query.db"))
	}()

	var (
		nextPageToken string = ""
		partList      []*TObject
		err           error
	)
	ctx := context.Background()

	selectorFn := func(obj *TObject) (bool, error) {
		return strings.Contains(obj.MyString, "flying"), nil
	}
	collected := []*TObject{}
	for {
		partList, nextPageToken, err = Query(ctx, 
            TObj, selectorFn, int32(count/pageSize), nextPageToken)
		if err != nil {
			panic(err)
		}
		collected = append(collected, partList...)
		if nextPageToken == "" {
			break
		}
	}
	for idx, obj := range collected {
		log.Printf("%d: [%v]\n", idx, obj)
	}
}

License

Shdb is released under the Apache 2.0 license. See LICENSE.txt

Documentation

Overview

Copyright 2023 Shenry Tech AB

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Examples

Constants

View Source
const (
	InvalidWatchEvent = 0
	EventCreated      = 1
	EventUpdated      = 2
	EventDeleted      = 3
)

Events reflecting life-cycle changes to an object

Variables

View Source
var (
	ErrNotAnObject      = errors.New("not an object type")
	ErrInvalidType      = errors.New("invalid type")
	ErrNotFound         = errors.New("not found")
	ErrSessionInvalid   = errors.New("session invalid")
	ErrContextCancelled = errors.New("context cancelled")
	ErrDatabaseCorrupt  = errors.New("database corrupt")
)
View Source
var (
	// optional shdb.v1.Shdb_Message_Options shdb_options = 52000;
	E_ShdbOptions = &file_pb_shdb_v1_shdb_proto_extTypes[0]
	// optional string shdb_type = 51234;
	E_ShdbType = &file_pb_shdb_v1_shdb_proto_extTypes[1]
	// optional string shdb_aliases = 51235;
	E_ShdbAliases = &file_pb_shdb_v1_shdb_proto_extTypes[2]
	// optional bytes shdb_type_key = 51236;
	E_ShdbTypeKey = &file_pb_shdb_v1_shdb_proto_extTypes[3]
)

Extension fields to descriptorpb.MessageOptions.

View Source
var File_pb_shdb_v1_shdb_proto protoreflect.FileDescriptor
View Source
var File_pb_shdb_v1_test_proto protoreflect.FileDescriptor
View Source
var ObjectService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "shdb.v1.ObjectService",
	HandlerType: (*ObjectServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "List",
			Handler:    _ObjectService_List_Handler,
		},
		{
			MethodName: "Get",
			Handler:    _ObjectService_Get_Handler,
		},
		{
			MethodName: "Create",
			Handler:    _ObjectService_Create_Handler,
		},
		{
			MethodName: "Update",
			Handler:    _ObjectService_Update_Handler,
		},
		{
			MethodName: "Delete",
			Handler:    _ObjectService_Delete_Handler,
		},
		{
			MethodName: "GetSchema",
			Handler:    _ObjectService_GetSchema_Handler,
		},
		{
			MethodName: "GetTypeNames",
			Handler:    _ObjectService_GetTypeNames_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "StreamRefs",
			Handler:       _ObjectService_StreamRefs_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "pb/shdb/v1/shdb.proto",
}

ObjectService_ServiceDesc is the grpc.ServiceDesc for ObjectService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var TypeKeyAll = TypeKey{0xff, 0xff, 0xff, 0xff}

Functions

func Close

func Close() error

Close the backing database

func Create

func Create[T IObject](typeKey TypeKey) (t T, err error)

Create just creates the memory for an IObject without initializing the Metadata

func Delete

func Delete[T IObject](tid TypeId) (T, error)

Delete an object from the database based on the type and id. The old value is returned

func DeleteAll added in v1.0.2

func DeleteAll(tk TypeKey) error

Delete all objects of a specific type from the database.

func Get

func Get[T IObject](tid TypeId) (T, error)

Get an object from the database based on the type and id of the object.

func GetAll

func GetAll[T IObject](typeKey TypeKey) ([]T, error)

GetAll returns all objects in database of a specific type

func GetFirst

func GetFirst[T IObject](typeKey TypeKey, selector func(obj T) bool) (T, error)

GetOne returns one of the objects in the database with the specified type that matches the selector function. The selector should return true for a match and false otherwise when presented with an object.

func GetRef added in v1.0.1

func GetRef[T IObject](ref *ObjRef) (T, error)

GetRef returns an object from the database based on an ObjRef

func Init

func Init(dbFile string)

Init initializes the backing database.

func List

func List[T IObject](ctx context.Context, typ TypeKey, pageSize int32, pageToken string) (result []T, nextPageToken string, err error)

List all objects pertaining to a specific type. For arguments and paging see `Query` method.

func LoadSchema added in v1.0.2

func LoadSchema() (*descriptorpb.FileDescriptorSet, error)

func MustNew

func MustNew[T IObject](typeKey TypeKey) T

MustNew is like `New` but panics if there is an error

func New

func New[T IObject](typeKey TypeKey) (obj T, err error)

New creates a new IObject based on the type key and initializes the Metadata fields.

func Put

func Put[T IObject](val ...T) error

Put creates objects in the database. If the object already existed it will be overwritten.

func Query

func Query[T IObject](ctx context.Context, typ TypeKey, selectFn func(obj T) (bool, error), pageSize int32, pageToken string) (result []T, nextPageToken string, err error)

Query returns all objects of a specific type matching a selector function. Paging of the results is implemented using a pageSize and a token. If there are more results available after pageSize items have been returned a non-empty nextPageToken is returned that can be used to retrieve a new page of results. If nextPageToken is the empty string, no more results are available.

Example
Init(path.Join(os.TempDir(), "example_query.db"))
count := 100
pageSize := 10

list := []*TObject{}
for k := 0; k < count; k++ {
	tObj := MustNew[*TObject](TObj)
	tObj.MyInt = uint64(k)
	list = append(list, tObj)
}
if err := Put(list...); err != nil {
	panic(err)
}

defer func() {
	Close()
	os.Remove(path.Join(os.TempDir(), "example_query.db"))
}()

var (
	nextPageToken string = ""
	partList      []*TObject
	err           error
)
ctx := context.Background()

selectorFn := func(obj *TObject) (bool, error) {
	return strings.Contains(obj.MyString, "flying"), nil
}
collected := []*TObject{}
for {
	partList, nextPageToken, err = Query(ctx, TObj, selectorFn, int32(count/pageSize), nextPageToken)
	if err != nil {
		panic(err)
	}
	collected = append(collected, partList...)
	if nextPageToken == "" {
		break
	}
}
for idx, obj := range collected {
	log.Printf("%d: [%v]\n", idx, obj)
}
Output:

func RegisterObjectServiceServer added in v1.0.2

func RegisterObjectServiceServer(s grpc.ServiceRegistrar, srv ObjectServiceServer)

func RemoveWatcher

func RemoveWatcher(watcherId string) error

RemoveWatcher closes the eventCh for the watcher and removes the watcher.

func SearchProto

func SearchProto(m proto.Message, query func(s string) bool) (hits []string, err error)

SearchProto searches within the fields of the proto message forthe string provided. The result will contain a number of hits in the form - /[fieldName|@idx]/... Examples:

  • / - The object contained only one item and it matched
  • /myField - {"myField": <match>}
  • /field1/field2/@3 {"field1": {"field2": [1,2,<match>]}}

func StoreSchema added in v1.0.2

func StoreSchema(files protoregistry.Files) error

StoreSchema stores the current state of a protoregistry.Files object in the schema bucket.

func Unmarshal

func Unmarshal[T IObject](kv KeyVal) (T, error)

Unmarshal returns the IObject from a KeyVal binary representation

func UnmarshalMany

func UnmarshalMany[T IObject](kvs []KeyVal) ([]T, error)

UnmarshalMany unmarshals a list of KeyVal binary representations

func UnwatchType

func UnwatchType(watcherId string, typeKeys ...TypeKey) error

UnwatchType removes a list of TypeKeys from a watcher

func UnwatchTypeId

func UnwatchTypeId(watcherId string, tids ...TypeId) error

UnwatchTypeId removes a list of TypeIds from a watcher

func Update

func Update[T IObject](tid TypeId, updater func(obj T) (T, error)) (t T, err error)

Update an object in the database by using an updater function. The updated object is returned.

func WatchType

func WatchType(watcherId string, eventCh chan *EventInfo, typeKeys ...TypeKey) (string, error)

WatchType creates or updates a watcher by adding watches to new TypeKeys If the provided watcherId is the empty string, a new watcher is created and the eventCh must be specified. If watcherId is non-empty, then the eventCh can be set to nil The watcherId is returned.

func WatchTypeId

func WatchTypeId(watcherId string, eventCh chan *EventInfo, tids ...TypeId) (string, error)

WatchType creates or updates a watcher by adding watches to new TypeIds If the provided watcherId is the empty string, a new watcher is created and the eventCh must be specified. If watcherId is non-empty, then the eventCh can be set to nil The watcherId is returned.

Types

type Client added in v1.0.2

type Client struct {
	// contains filtered or unexported fields
}

func NewClient added in v1.0.2

func NewClient(ctx context.Context, cc *grpc.ClientConn) *Client

NewClient returns a new client for use with the API

func (*Client) Create added in v1.0.2

func (c *Client) Create(typ TypeKey) (IObject, error)

func (*Client) Delete added in v1.0.2

func (c *Client) Delete(tid TypeId) (IObject, error)

func (*Client) Get added in v1.0.2

func (c *Client) Get(tid TypeId) (IObject, error)

func (*Client) GetTypeNames added in v1.0.2

func (c *Client) GetTypeNames() (map[string][]string, error)

func (*Client) List added in v1.0.2

func (c *Client) List(tk TypeKey) ([]IObject, error)

func (*Client) SearchRef added in v1.0.2

func (c *Client) SearchRef(tk TypeKey, selector func(obj *ObjRef) bool) (chan *ObjRef, error)

func (*Client) TypeRegistry added in v1.0.2

func (c *Client) TypeRegistry() *TypeRegistry

func (*Client) Update added in v1.0.2

func (c *Client) Update(obj IObject) (IObject, error)

type CreateReq added in v1.0.2

type CreateReq struct {
	Type []byte `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	// contains filtered or unexported fields
}

func (*CreateReq) Descriptor deprecated added in v1.0.2

func (*CreateReq) Descriptor() ([]byte, []int)

Deprecated: Use CreateReq.ProtoReflect.Descriptor instead.

func (*CreateReq) GetType added in v1.0.2

func (x *CreateReq) GetType() []byte

func (*CreateReq) ProtoMessage added in v1.0.2

func (*CreateReq) ProtoMessage()

func (*CreateReq) ProtoReflect added in v1.0.2

func (x *CreateReq) ProtoReflect() protoreflect.Message

func (*CreateReq) Reset added in v1.0.2

func (x *CreateReq) Reset()

func (*CreateReq) String added in v1.0.2

func (x *CreateReq) String() string

type DeleteReq added in v1.0.2

type DeleteReq struct {
	Ref *ObjRef `protobuf:"bytes,1,opt,name=ref,proto3" json:"ref,omitempty"`
	// contains filtered or unexported fields
}

func (*DeleteReq) Descriptor deprecated added in v1.0.2

func (*DeleteReq) Descriptor() ([]byte, []int)

Deprecated: Use DeleteReq.ProtoReflect.Descriptor instead.

func (*DeleteReq) GetRef added in v1.0.2

func (x *DeleteReq) GetRef() *ObjRef

func (*DeleteReq) ProtoMessage added in v1.0.2

func (*DeleteReq) ProtoMessage()

func (*DeleteReq) ProtoReflect added in v1.0.2

func (x *DeleteReq) ProtoReflect() protoreflect.Message

func (*DeleteReq) Reset added in v1.0.2

func (x *DeleteReq) Reset()

func (*DeleteReq) String added in v1.0.2

func (x *DeleteReq) String() string

type DynObject added in v1.0.2

type DynObject struct {
	*dynamicpb.Message
}

func (*DynObject) GetMetadata added in v1.0.2

func (o *DynObject) GetMetadata() *Metadata

type EventInfo

type EventInfo struct {
	Kind     int
	Tid      TypeId
	Object   IObject
	Previous IObject
}

EventInfo contains the information about a specific life cycle event

type GetReq added in v1.0.2

type GetReq struct {
	Ref *ObjRef `protobuf:"bytes,1,opt,name=ref,proto3" json:"ref,omitempty"`
	// contains filtered or unexported fields
}

func (*GetReq) Descriptor deprecated added in v1.0.2

func (*GetReq) Descriptor() ([]byte, []int)

Deprecated: Use GetReq.ProtoReflect.Descriptor instead.

func (*GetReq) GetRef added in v1.0.2

func (x *GetReq) GetRef() *ObjRef

func (*GetReq) ProtoMessage added in v1.0.2

func (*GetReq) ProtoMessage()

func (*GetReq) ProtoReflect added in v1.0.2

func (x *GetReq) ProtoReflect() protoreflect.Message

func (*GetReq) Reset added in v1.0.2

func (x *GetReq) Reset()

func (*GetReq) String added in v1.0.2

func (x *GetReq) String() string

type GetTypeNamesRsp added in v1.0.2

type GetTypeNamesRsp struct {
	TypeAliases []*GetTypeNamesRsp_TypeAliases `protobuf:"bytes,1,rep,name=type_aliases,json=typeAliases,proto3" json:"type_aliases,omitempty"`
	// contains filtered or unexported fields
}

func (*GetTypeNamesRsp) Descriptor deprecated added in v1.0.2

func (*GetTypeNamesRsp) Descriptor() ([]byte, []int)

Deprecated: Use GetTypeNamesRsp.ProtoReflect.Descriptor instead.

func (*GetTypeNamesRsp) GetTypeAliases added in v1.0.2

func (x *GetTypeNamesRsp) GetTypeAliases() []*GetTypeNamesRsp_TypeAliases

func (*GetTypeNamesRsp) ProtoMessage added in v1.0.2

func (*GetTypeNamesRsp) ProtoMessage()

func (*GetTypeNamesRsp) ProtoReflect added in v1.0.2

func (x *GetTypeNamesRsp) ProtoReflect() protoreflect.Message

func (*GetTypeNamesRsp) Reset added in v1.0.2

func (x *GetTypeNamesRsp) Reset()

func (*GetTypeNamesRsp) String added in v1.0.2

func (x *GetTypeNamesRsp) String() string

type GetTypeNamesRsp_TypeAliases added in v1.0.2

type GetTypeNamesRsp_TypeAliases struct {
	Fullname string   `protobuf:"bytes,1,opt,name=fullname,proto3" json:"fullname,omitempty"`
	Aliases  []string `protobuf:"bytes,2,rep,name=aliases,proto3" json:"aliases,omitempty"`
	// contains filtered or unexported fields
}

func (*GetTypeNamesRsp_TypeAliases) Descriptor deprecated added in v1.0.2

func (*GetTypeNamesRsp_TypeAliases) Descriptor() ([]byte, []int)

Deprecated: Use GetTypeNamesRsp_TypeAliases.ProtoReflect.Descriptor instead.

func (*GetTypeNamesRsp_TypeAliases) GetAliases added in v1.0.2

func (x *GetTypeNamesRsp_TypeAliases) GetAliases() []string

func (*GetTypeNamesRsp_TypeAliases) GetFullname added in v1.0.2

func (x *GetTypeNamesRsp_TypeAliases) GetFullname() string

func (*GetTypeNamesRsp_TypeAliases) ProtoMessage added in v1.0.2

func (*GetTypeNamesRsp_TypeAliases) ProtoMessage()

func (*GetTypeNamesRsp_TypeAliases) ProtoReflect added in v1.0.2

func (*GetTypeNamesRsp_TypeAliases) Reset added in v1.0.2

func (x *GetTypeNamesRsp_TypeAliases) Reset()

func (*GetTypeNamesRsp_TypeAliases) String added in v1.0.2

func (x *GetTypeNamesRsp_TypeAliases) String() string

type IObject

type IObject interface {
	proto.Message
	GetMetadata() *Metadata
}

IObject is the interface for all objects in the dataabase. They all should stem from a protobuf message that looks like this:

	message TObject {
  		shdb.Metadata metadata = 1;
  		string my_field = 2;
  		uint64 my_int = 3;
	}

type KeyVal

type KeyVal struct {
	TypeId
	Value []byte
}

KeyVal is the binary representation of an IObject as it is stored in the database

func GetAllKV

func GetAllKV(typeKey TypeKey) ([]KeyVal, error)

GetAllKV returns all KeyVals of the database.

func Marshal

func Marshal[T IObject](objs ...T) (ret []KeyVal, err error)

Marshal returns a list of KeyVal binary representation representing a list of IObjects

type ListReq added in v1.0.2

type ListReq struct {
	Type      []byte `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	PageSize  int32  `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
	PageToken string `protobuf:"bytes,3,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"`
	// contains filtered or unexported fields
}

func (*ListReq) Descriptor deprecated added in v1.0.2

func (*ListReq) Descriptor() ([]byte, []int)

Deprecated: Use ListReq.ProtoReflect.Descriptor instead.

func (*ListReq) GetPageSize added in v1.0.2

func (x *ListReq) GetPageSize() int32

func (*ListReq) GetPageToken added in v1.0.2

func (x *ListReq) GetPageToken() string

func (*ListReq) GetType added in v1.0.2

func (x *ListReq) GetType() []byte

func (*ListReq) ProtoMessage added in v1.0.2

func (*ListReq) ProtoMessage()

func (*ListReq) ProtoReflect added in v1.0.2

func (x *ListReq) ProtoReflect() protoreflect.Message

func (*ListReq) Reset added in v1.0.2

func (x *ListReq) Reset()

func (*ListReq) String added in v1.0.2

func (x *ListReq) String() string

type ListRsp added in v1.0.2

type ListRsp struct {
	Objects       []*Object `protobuf:"bytes,1,rep,name=objects,proto3" json:"objects,omitempty"`
	NextPageToken string    `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"`
	// contains filtered or unexported fields
}

func (*ListRsp) Descriptor deprecated added in v1.0.2

func (*ListRsp) Descriptor() ([]byte, []int)

Deprecated: Use ListRsp.ProtoReflect.Descriptor instead.

func (*ListRsp) GetNextPageToken added in v1.0.2

func (x *ListRsp) GetNextPageToken() string

func (*ListRsp) GetObjects added in v1.0.2

func (x *ListRsp) GetObjects() []*Object

func (*ListRsp) ProtoMessage added in v1.0.2

func (*ListRsp) ProtoMessage()

func (*ListRsp) ProtoReflect added in v1.0.2

func (x *ListRsp) ProtoReflect() protoreflect.Message

func (*ListRsp) Reset added in v1.0.2

func (x *ListRsp) Reset()

func (*ListRsp) String added in v1.0.2

func (x *ListRsp) String() string

type MessageInfo added in v1.0.2

type MessageInfo struct {
	Fullname       string
	Aliases        []string
	PrintTemplates map[string]string
	TypeKey        TypeKey
	MessageType    protoreflect.MessageType
	IsDynamic      bool
}

type Metadata

type Metadata struct {
	Type        []byte                 `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Uuid        []byte                 `protobuf:"bytes,2,opt,name=uuid,proto3" json:"uuid,omitempty"`
	Labels      []string               `protobuf:"bytes,3,rep,name=labels,proto3" json:"labels,omitempty"`
	Description string                 `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
	CreatedAt   *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	UpdatedAt   *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
	// contains filtered or unexported fields
}

func (*Metadata) Descriptor deprecated

func (*Metadata) Descriptor() ([]byte, []int)

Deprecated: Use Metadata.ProtoReflect.Descriptor instead.

func (*Metadata) Fill added in v1.0.1

func (m *Metadata) Fill() error

Fill the metadata with fields that are missing

func (*Metadata) GetCreatedAt

func (x *Metadata) GetCreatedAt() *timestamppb.Timestamp

func (*Metadata) GetDescription

func (x *Metadata) GetDescription() string

func (*Metadata) GetLabels

func (x *Metadata) GetLabels() []string

func (*Metadata) GetType

func (x *Metadata) GetType() []byte

func (*Metadata) GetUpdatedAt

func (x *Metadata) GetUpdatedAt() *timestamppb.Timestamp

func (*Metadata) GetUuid

func (x *Metadata) GetUuid() []byte

func (*Metadata) GetUuidAsString added in v1.0.1

func (m *Metadata) GetUuidAsString() (string, error)

GetUuidAsString returns the UUID as a string

func (*Metadata) GetUuidAsUUID added in v1.0.1

func (m *Metadata) GetUuidAsUUID() (uuid.UUID, error)

GetUuidAsUUID returns the UUID as a uuid.UUID

func (*Metadata) ProtoMessage

func (*Metadata) ProtoMessage()

func (*Metadata) ProtoReflect

func (x *Metadata) ProtoReflect() protoreflect.Message

func (*Metadata) Ref added in v1.0.1

func (m *Metadata) Ref() *ObjRef

Return the Metadata as an *ObjRef

func (*Metadata) Reset

func (x *Metadata) Reset()

func (*Metadata) String

func (x *Metadata) String() string

func (*Metadata) TypeId

func (m *Metadata) TypeId() TypeId

TypeId returns the TypeId representation of the type and Id

type ObjRef added in v1.0.1

type ObjRef struct {
	Type []byte `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Uuid []byte `protobuf:"bytes,2,opt,name=uuid,proto3" json:"uuid,omitempty"`
	// contains filtered or unexported fields
}

func MustParseObjRef added in v1.0.2

func MustParseObjRef(typeKey TypeKey, id interface{}) *ObjRef

func ObjRefFromUUID added in v1.0.2

func ObjRefFromUUID(typeKey TypeKey, id string) (*ObjRef, error)

func ParseObjRef added in v1.0.2

func ParseObjRef(typeKey TypeKey, id interface{}) (*ObjRef, error)

func SearchRef added in v1.0.2

func SearchRef(ctx context.Context,
	selector func(*ObjRef) bool,
	pageSize int32,
	pageToken string) (result []*ObjRef, nextPageToken string, err error)

SearchRef searches the Ref of objects For paging functionality see `Query` method.

func UnmarshalObjRef added in v1.0.1

func UnmarshalObjRef(data []byte) (*ObjRef, error)

UnmarshalObjRef a byte slice into ObjRef

func (*ObjRef) Descriptor deprecated added in v1.0.1

func (*ObjRef) Descriptor() ([]byte, []int)

Deprecated: Use ObjRef.ProtoReflect.Descriptor instead.

func (*ObjRef) Equal added in v1.0.2

func (r *ObjRef) Equal(other *ObjRef) bool

func (*ObjRef) GetType added in v1.0.1

func (x *ObjRef) GetType() []byte

func (*ObjRef) GetUuid added in v1.0.1

func (x *ObjRef) GetUuid() []byte

func (*ObjRef) Marshal added in v1.0.1

func (r *ObjRef) Marshal() []byte

Marshal an ObjRef to a byte slice

func (*ObjRef) ProtoMessage added in v1.0.1

func (*ObjRef) ProtoMessage()

func (*ObjRef) ProtoReflect added in v1.0.1

func (x *ObjRef) ProtoReflect() protoreflect.Message

func (*ObjRef) Reset added in v1.0.1

func (x *ObjRef) Reset()

func (*ObjRef) String added in v1.0.1

func (x *ObjRef) String() string

func (*ObjRef) TypeId added in v1.0.1

func (r *ObjRef) TypeId() *TypeId

TypeId returns the ObjRef as a *TypeId

func (*ObjRef) UUID added in v1.0.2

func (r *ObjRef) UUID() uuid.UUID

type Object added in v1.0.2

type Object struct {
	Key   []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*Object) Descriptor deprecated added in v1.0.2

func (*Object) Descriptor() ([]byte, []int)

Deprecated: Use Object.ProtoReflect.Descriptor instead.

func (*Object) GetKey added in v1.0.2

func (x *Object) GetKey() []byte

func (*Object) GetValue added in v1.0.2

func (x *Object) GetValue() []byte

func (*Object) ProtoMessage added in v1.0.2

func (*Object) ProtoMessage()

func (*Object) ProtoReflect added in v1.0.2

func (x *Object) ProtoReflect() protoreflect.Message

func (*Object) Reset added in v1.0.2

func (x *Object) Reset()

func (*Object) String added in v1.0.2

func (x *Object) String() string

type ObjectServiceClient added in v1.0.2

type ObjectServiceClient interface {
	List(ctx context.Context, in *ListReq, opts ...grpc.CallOption) (*ListRsp, error)
	Get(ctx context.Context, in *GetReq, opts ...grpc.CallOption) (*Object, error)
	Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*Object, error)
	Update(ctx context.Context, in *UpdateReq, opts ...grpc.CallOption) (*Object, error)
	Delete(ctx context.Context, in *DeleteReq, opts ...grpc.CallOption) (*Object, error)
	StreamRefs(ctx context.Context, in *StreamRefReq, opts ...grpc.CallOption) (ObjectService_StreamRefsClient, error)
	GetSchema(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*descriptorpb.FileDescriptorSet, error)
	GetTypeNames(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetTypeNamesRsp, error)
}

ObjectServiceClient is the client API for ObjectService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewObjectServiceClient added in v1.0.2

func NewObjectServiceClient(cc grpc.ClientConnInterface) ObjectServiceClient

type ObjectServiceServer added in v1.0.2

type ObjectServiceServer interface {
	List(context.Context, *ListReq) (*ListRsp, error)
	Get(context.Context, *GetReq) (*Object, error)
	Create(context.Context, *CreateReq) (*Object, error)
	Update(context.Context, *UpdateReq) (*Object, error)
	Delete(context.Context, *DeleteReq) (*Object, error)
	StreamRefs(*StreamRefReq, ObjectService_StreamRefsServer) error
	GetSchema(context.Context, *emptypb.Empty) (*descriptorpb.FileDescriptorSet, error)
	GetTypeNames(context.Context, *emptypb.Empty) (*GetTypeNamesRsp, error)
	// contains filtered or unexported methods
}

ObjectServiceServer is the server API for ObjectService service. All implementations must embed UnimplementedObjectServiceServer for forward compatibility

type ObjectService_StreamRefsClient added in v1.0.2

type ObjectService_StreamRefsClient interface {
	Recv() (*ObjRef, error)
	grpc.ClientStream
}

type ObjectService_StreamRefsServer added in v1.0.2

type ObjectService_StreamRefsServer interface {
	Send(*ObjRef) error
	grpc.ServerStream
}

type SearchHit

type SearchHit struct {
	Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	Hits     []string  `protobuf:"bytes,2,rep,name=hits,proto3" json:"hits,omitempty"`
	// contains filtered or unexported fields
}

func (*SearchHit) Descriptor deprecated

func (*SearchHit) Descriptor() ([]byte, []int)

Deprecated: Use SearchHit.ProtoReflect.Descriptor instead.

func (*SearchHit) GetHits

func (x *SearchHit) GetHits() []string

func (*SearchHit) GetMetadata

func (x *SearchHit) GetMetadata() *Metadata

func (*SearchHit) ProtoMessage

func (*SearchHit) ProtoMessage()

func (*SearchHit) ProtoReflect

func (x *SearchHit) ProtoReflect() protoreflect.Message

func (*SearchHit) Reset

func (x *SearchHit) Reset()

func (*SearchHit) String

func (x *SearchHit) String() string

type SearchResult

type SearchResult struct {
	Hits []*SearchHit `protobuf:"bytes,1,rep,name=hits,proto3" json:"hits,omitempty"`
	// contains filtered or unexported fields
}
func Search(ctx context.Context,
	typ TypeKey,
	selector func(string) bool,
	pageSize int32,
	pageToken string) (result *SearchResult, nextPageToken string, err error)

Search searches the values of the fields of objects pertaining to a type by calling a selector function for each field in all objects. For paging functionality see `Query` method.

func (*SearchResult) Descriptor deprecated

func (*SearchResult) Descriptor() ([]byte, []int)

Deprecated: Use SearchResult.ProtoReflect.Descriptor instead.

func (*SearchResult) GetHits

func (x *SearchResult) GetHits() []*SearchHit

func (*SearchResult) ProtoMessage

func (*SearchResult) ProtoMessage()

func (*SearchResult) ProtoReflect

func (x *SearchResult) ProtoReflect() protoreflect.Message

func (*SearchResult) Reset

func (x *SearchResult) Reset()

func (*SearchResult) String

func (x *SearchResult) String() string

type Server added in v1.0.2

type Server struct {
	UnimplementedObjectServiceServer
	// contains filtered or unexported fields
}

func NewServer added in v1.0.2

func NewServer(ctx context.Context, grpcServer *grpc.Server, typeReg *TypeRegistry) *Server

func (*Server) Create added in v1.0.2

func (s *Server) Create(ctx context.Context, req *CreateReq) (*Object, error)

func (*Server) Delete added in v1.0.2

func (s *Server) Delete(ctx context.Context, req *DeleteReq) (*Object, error)

func (*Server) Get added in v1.0.2

func (s *Server) Get(ctx context.Context, req *GetReq) (*Object, error)

func (*Server) GetSchema added in v1.0.2

func (s *Server) GetSchema(ctx context.Context, req *emptypb.Empty) (*descriptorpb.FileDescriptorSet, error)

func (*Server) GetTypeNames added in v1.0.2

func (s *Server) GetTypeNames(ctx context.Context, req *emptypb.Empty) (*GetTypeNamesRsp, error)

func (*Server) List added in v1.0.2

func (s *Server) List(ctx context.Context, req *ListReq) (*ListRsp, error)

func (*Server) StreamRefs added in v1.0.2

func (s *Server) StreamRefs(req *StreamRefReq, stream ObjectService_StreamRefsServer) error

func (*Server) Update added in v1.0.2

func (s *Server) Update(ctx context.Context, req *UpdateReq) (*Object, error)

type Shdb_Message_Options added in v1.0.2

type Shdb_Message_Options struct {
	Type           string            `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Aliases        []string          `protobuf:"bytes,2,rep,name=aliases,proto3" json:"aliases,omitempty"`
	TypeKey        []byte            `protobuf:"bytes,3,opt,name=type_key,json=typeKey,proto3" json:"type_key,omitempty"`
	PrintTemplates map[string]string `` /* 191-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Shdb_Message_Options) Descriptor deprecated added in v1.0.2

func (*Shdb_Message_Options) Descriptor() ([]byte, []int)

Deprecated: Use Shdb_Message_Options.ProtoReflect.Descriptor instead.

func (*Shdb_Message_Options) GetAliases added in v1.0.2

func (x *Shdb_Message_Options) GetAliases() []string

func (*Shdb_Message_Options) GetPrintTemplates added in v1.0.2

func (x *Shdb_Message_Options) GetPrintTemplates() map[string]string

func (*Shdb_Message_Options) GetType added in v1.0.2

func (x *Shdb_Message_Options) GetType() string

func (*Shdb_Message_Options) GetTypeKey added in v1.0.2

func (x *Shdb_Message_Options) GetTypeKey() []byte

func (*Shdb_Message_Options) ProtoMessage added in v1.0.2

func (*Shdb_Message_Options) ProtoMessage()

func (*Shdb_Message_Options) ProtoReflect added in v1.0.2

func (x *Shdb_Message_Options) ProtoReflect() protoreflect.Message

func (*Shdb_Message_Options) Reset added in v1.0.2

func (x *Shdb_Message_Options) Reset()

func (*Shdb_Message_Options) String added in v1.0.2

func (x *Shdb_Message_Options) String() string

type StreamRefReq added in v1.0.2

type StreamRefReq struct {
	TypeKey []byte `protobuf:"bytes,1,opt,name=type_key,json=typeKey,proto3" json:"type_key,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamRefReq) Descriptor deprecated added in v1.0.2

func (*StreamRefReq) Descriptor() ([]byte, []int)

Deprecated: Use StreamRefReq.ProtoReflect.Descriptor instead.

func (*StreamRefReq) GetTypeKey added in v1.0.2

func (x *StreamRefReq) GetTypeKey() []byte

func (*StreamRefReq) ProtoMessage added in v1.0.2

func (*StreamRefReq) ProtoMessage()

func (*StreamRefReq) ProtoReflect added in v1.0.2

func (x *StreamRefReq) ProtoReflect() protoreflect.Message

func (*StreamRefReq) Reset added in v1.0.2

func (x *StreamRefReq) Reset()

func (*StreamRefReq) String added in v1.0.2

func (x *StreamRefReq) String() string

type TObject

type TObject struct {
	Metadata  *Metadata              `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	MyInt     uint64                 `protobuf:"varint,2,opt,name=my_int,json=myInt,proto3" json:"my_int,omitempty"`
	MyString  string                 `protobuf:"bytes,3,opt,name=my_string,json=myString,proto3" json:"my_string,omitempty"`
	Timestamp *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Any       *anypb.Any             `protobuf:"bytes,5,opt,name=any,proto3" json:"any,omitempty"`
	// contains filtered or unexported fields
}

func (*TObject) Descriptor deprecated

func (*TObject) Descriptor() ([]byte, []int)

Deprecated: Use TObject.ProtoReflect.Descriptor instead.

func (*TObject) GetAny added in v1.0.2

func (x *TObject) GetAny() *anypb.Any

func (*TObject) GetMetadata

func (x *TObject) GetMetadata() *Metadata

func (*TObject) GetMyInt

func (x *TObject) GetMyInt() uint64

func (*TObject) GetMyString added in v1.0.2

func (x *TObject) GetMyString() string

func (*TObject) GetTimestamp added in v1.0.2

func (x *TObject) GetTimestamp() *timestamppb.Timestamp

func (*TObject) ProtoMessage

func (*TObject) ProtoMessage()

func (*TObject) ProtoReflect

func (x *TObject) ProtoReflect() protoreflect.Message

func (*TObject) Reset

func (x *TObject) Reset()

func (*TObject) String

func (x *TObject) String() string

type TypeId

type TypeId struct {
	// contains filtered or unexported fields
}

TypeId is the key in the key-value database that is used to store IObjects. It has a memory layout like:

[b0 .. b3]		TypeKey
[b4 .. b20]		Binary representation of an UUID

func GetTypeId

func GetTypeId(obj IObject) *TypeId

GetTypeId returns the TypeID from the Metadata of an IObject

func MarshalTypeId

func MarshalTypeId(data []byte) *TypeId

MarshalTypeId creates a TypeId from a []byte slice

func MustParseTypeId added in v1.0.2

func MustParseTypeId(typeKey TypeKey, id interface{}) TypeId

func NewTypeId

func NewTypeId(typeKey TypeKey, id []byte) *TypeId

NewTypeId creates a new TypeId based on TypeKey and UUID (Byte version)

func ParseTypeId added in v1.0.2

func ParseTypeId(typeKey TypeKey, id interface{}) (tid TypeId, err error)

func TypeIdFromString

func TypeIdFromString(str string) (*TypeId, error)

TypeIdFromString returns a TypeId from an URL-encoded string

func (*TypeId) Equal

func (k *TypeId) Equal(other *TypeId) bool

Equal compares two TypeIds and return true if they are equal

func (*TypeId) Key

func (k *TypeId) Key() []byte

Key returns the TypeId as a []byte slice

func (*TypeId) SetType

func (k *TypeId) SetType(keyType TypeKey)

SetType sets the type of a TypeId

func (*TypeId) SetUuid

func (k *TypeId) SetUuid(id uuid.UUID)

SetUuid sets thte id (as uuid.UUID) of a TypeId

func (*TypeId) SetUuidBytes

func (k *TypeId) SetUuidBytes(id []byte)

SetUuidBytes sets the Id (as bytes) of a TypeId

func (*TypeId) String

func (k *TypeId) String() string

String returns the URL-encoded string of the TypeId

func (TypeId) TypeKey

func (k TypeId) TypeKey() TypeKey

TypeKey returns the TypeKey of a TypeId

func (TypeId) Uuid

func (k TypeId) Uuid() uuid.UUID

Uuid returns the uuid.UUID of the id of a TypeID

func (TypeId) UuidBytes

func (k TypeId) UuidBytes() []byte

UuidBytes returns the byte version of the id of a TypeId

type TypeKey

type TypeKey = [4]byte

TypeKey is the four bytes that identifies the type of an object

func TypeKeyOf added in v1.0.2

func TypeKeyOf(fullname string) TypeKey

type TypeRegistry added in v1.0.2

type TypeRegistry struct {
	// contains filtered or unexported fields
}

func NewTypeRegistry added in v1.0.2

func NewTypeRegistry() *TypeRegistry

func (*TypeRegistry) AddFile added in v1.0.2

func (*TypeRegistry) AddFileFromProtoFileDescriptor added in v1.0.2

func (r *TypeRegistry) AddFileFromProtoFileDescriptor(fd *descriptorpb.FileDescriptorProto) error

func (*TypeRegistry) CreateEmptyObject added in v1.0.2

func (r *TypeRegistry) CreateEmptyObject(tk TypeKey) (IObject, error)

func (*TypeRegistry) CreateObject added in v1.0.2

func (r *TypeRegistry) CreateObject(spec interface{}) (IObject, error)

func (*TypeRegistry) GetFileDescriptorSet added in v1.0.2

func (r *TypeRegistry) GetFileDescriptorSet() *descriptorpb.FileDescriptorSet

func (*TypeRegistry) GetMessageInfo added in v1.0.2

func (r *TypeRegistry) GetMessageInfo(tk TypeKey) (MessageInfo, error)

func (*TypeRegistry) GetTypeKeyFromToA added in v1.0.2

func (r *TypeRegistry) GetTypeKeyFromToA(toa string) (TypeKey, error)

func (*TypeRegistry) GetTypeNames added in v1.0.2

func (r *TypeRegistry) GetTypeNames() map[string][]string

func (*TypeRegistry) LoadSchema added in v1.0.2

func (r *TypeRegistry) LoadSchema() (err error)

func (*TypeRegistry) StoreSchema added in v1.0.2

func (r *TypeRegistry) StoreSchema() error

func (*TypeRegistry) Unmarshal added in v1.0.2

func (r *TypeRegistry) Unmarshal(key []byte, value []byte) (IObject, error)

func (*TypeRegistry) UseFileDescriptorSet added in v1.0.2

func (r *TypeRegistry) UseFileDescriptorSet(fds *descriptorpb.FileDescriptorSet) (err error)

type UnimplementedObjectServiceServer added in v1.0.2

type UnimplementedObjectServiceServer struct {
}

UnimplementedObjectServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedObjectServiceServer) Create added in v1.0.2

func (UnimplementedObjectServiceServer) Delete added in v1.0.2

func (UnimplementedObjectServiceServer) Get added in v1.0.2

func (UnimplementedObjectServiceServer) GetSchema added in v1.0.2

func (UnimplementedObjectServiceServer) GetTypeNames added in v1.0.2

func (UnimplementedObjectServiceServer) List added in v1.0.2

func (UnimplementedObjectServiceServer) StreamRefs added in v1.0.2

func (UnimplementedObjectServiceServer) Update added in v1.0.2

type UnsafeObjectServiceServer added in v1.0.2

type UnsafeObjectServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeObjectServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ObjectServiceServer will result in compilation errors.

type UpdateReq added in v1.0.2

type UpdateReq struct {
	Object *Object `protobuf:"bytes,1,opt,name=object,proto3" json:"object,omitempty"`
	// contains filtered or unexported fields
}

func (*UpdateReq) Descriptor deprecated added in v1.0.2

func (*UpdateReq) Descriptor() ([]byte, []int)

Deprecated: Use UpdateReq.ProtoReflect.Descriptor instead.

func (*UpdateReq) GetObject added in v1.0.2

func (x *UpdateReq) GetObject() *Object

func (*UpdateReq) ProtoMessage added in v1.0.2

func (*UpdateReq) ProtoMessage()

func (*UpdateReq) ProtoReflect added in v1.0.2

func (x *UpdateReq) ProtoReflect() protoreflect.Message

func (*UpdateReq) Reset added in v1.0.2

func (x *UpdateReq) Reset()

func (*UpdateReq) String added in v1.0.2

func (x *UpdateReq) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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