inmemdb

package module
v0.0.0-...-fb959a6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 14 Imported by: 0

README

inmemdb

simple in-memory datatables with join iterators on column indexes, compatible with sqlx longtime store

Documentation

Index

Constants

View Source
const (
	TagValidate = "validate"

	Tag     = "store"
	TagName = "db"

	TagOptionIgnore     = "-"
	TagOptionCascade    = "cascade"
	TagOptionForeignKey = "foreignKey"
	TagOptionManyToMany = "many2many"

	IDField        = "ID"
	CreatedAtField = "CreatedAt"
	UpdatedAtField = "UpdatedAt"
	DeletedAtField = "DeletedAt"
)

Variables

This section is empty.

Functions

func ByteSlice2String

func ByteSlice2String(bs []byte) string

func ConvertToType

func ConvertToType(v interface{}, to reflect.Type) (interface{}, error)

func FixIDAccHeap

func FixIDAccHeap(h *IDAccHeap, i int)

func GetBuffer

func GetBuffer() *bytes.Buffer

func GetFieldByName

func GetFieldByName(typ reflect.Type, name string) (reflect.StructField, error)

func GetFieldValueByName

func GetFieldValueByName(val reflect.Value, name string) (reflect.Value, error)

func GetUniqTypeName

func GetUniqTypeName(typ reflect.Type) string

func InitIDAccHeap

func InitIDAccHeap(h *IDAccHeap)

func JsonFieldName

func JsonFieldName(field reflect.StructField) string

func PushIDAccHeap

func PushIDAccHeap(h *IDAccHeap, x ElemHeapIDAcc)

func PutBuffer

func PutBuffer(b *bytes.Buffer)

func ValidateValuer

func ValidateValuer(field reflect.Value) interface{}

Types

type ColumnIterator

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

func NewColumnIterator

func NewColumnIterator(c IterColumner, filterSkip func(idx ModelSortable) bool) *ColumnIterator

func (*ColumnIterator) Cardinality

func (iter *ColumnIterator) Cardinality() int

func (*ColumnIterator) Clone

func (iter *ColumnIterator) Clone() IDIterator

func (*ColumnIterator) HasNext

func (iter *ColumnIterator) HasNext() bool

func (*ColumnIterator) JumpTo

func (iter *ColumnIterator) JumpTo(id ModelSortable) bool

func (*ColumnIterator) NextID

func (iter *ColumnIterator) NextID() ModelSortable

func (*ColumnIterator) Range

func (iter *ColumnIterator) Range() (ModelSortable, ModelSortable)

type Converter

type Converter interface {
	ConvertFrom(v interface{}) error
}

type ElemHeapIDAcc

type ElemHeapIDAcc struct {
	ID       ModelSortable // Value of this element.
	Iterator IDIterator    // Which list this element comes from.
}

func PopIDAccHeap

func PopIDAccHeap(h *IDAccHeap) ElemHeapIDAcc

func RemoveIDAccHeap

func RemoveIDAccHeap(h *IDAccHeap, i int) ElemHeapIDAcc

type ErrorForbidden

type ErrorForbidden struct {
	Message string
}

func (ErrorForbidden) Error

func (e ErrorForbidden) Error() string

type ErrorValidation

type ErrorValidation struct {
	ID interface{}

	Type             reflect.Type
	FieldDescription FieldDescription
	Validator        string
	Param            string
	Message          string
}

func (ErrorValidation) Error

func (e ErrorValidation) Error() string

func (*ErrorValidation) ToDesc

type ErrorValidations

type ErrorValidations []ErrorValidation

func MakeErrorValidations

func MakeErrorValidations(md ModelDescription, modelID interface{}, errs validator.ValidationErrors) (ErrorValidations, error)

func (ErrorValidations) Error

func (e ErrorValidations) Error() string

type FieldDescription

type FieldDescription struct {
	Idx           int                 // index in ModelDescription.Columns
	StructField   reflect.StructField // reflect field
	ElemType      reflect.Type        // type of field
	Name          string              // store name
	JsonName      string
	JsonOmitEmpty bool
	Nullable      bool
	Skip          bool
	IsForeignKey  bool
	RelatedColumn *FieldDescription

	Relation Relation
}

FieldDescription - describe a field of model

func (*FieldDescription) IsStored

func (fd *FieldDescription) IsStored() bool

func (*FieldDescription) MarshalJSON

func (fd *FieldDescription) MarshalJSON() ([]byte, error)

func (*FieldDescription) MarshalText

func (fd *FieldDescription) MarshalText() (text []byte, err error)

func (FieldDescription) String

func (fd FieldDescription) String() string

type GreyHole

type GreyHole struct {
	T     reflect.Type
	V     interface{}
	Valid bool
}

func (*GreyHole) Scan

func (b *GreyHole) Scan(value interface{}) error

func (GreyHole) Value

func (b GreyHole) Value() (driver.Value, error)

type IDAccHeap

type IDAccHeap struct {
	Elems []ElemHeapIDAcc
}

func NewIDAccHeap

func NewIDAccHeap(capacity int) *IDAccHeap

func (*IDAccHeap) Clone

func (h *IDAccHeap) Clone() *IDAccHeap

func (*IDAccHeap) Len

func (h *IDAccHeap) Len() int

func (*IDAccHeap) Less

func (h *IDAccHeap) Less(i, j int) bool

func (*IDAccHeap) Pop

func (h *IDAccHeap) Pop() ElemHeapIDAcc

func (*IDAccHeap) Push

func (h *IDAccHeap) Push(x ElemHeapIDAcc)

func (*IDAccHeap) Swap

func (h *IDAccHeap) Swap(i, j int)

type IDIterator

type IDIterator interface {
	HasNext() bool
	NextID() ModelSortable
	JumpTo(ModelSortable) bool
	Range() (ModelSortable, ModelSortable)
	Cardinality() int
	Clone() IDIterator
}

type IntersectIterator

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

func NewIteratorIntersect

func NewIteratorIntersect() *IntersectIterator

func (*IntersectIterator) Append

func (iter *IntersectIterator) Append(iterator IDIterator)

func (*IntersectIterator) AppendDiff

func (iter *IntersectIterator) AppendDiff(iterator IDIterator)

at least one iterator needed for successful difference

func (*IntersectIterator) Cardinality

func (iter *IntersectIterator) Cardinality() int

func (*IntersectIterator) Clone

func (iter *IntersectIterator) Clone() IDIterator

func (*IntersectIterator) HasNext

func (iter *IntersectIterator) HasNext() bool

func (*IntersectIterator) Iter

func (iter *IntersectIterator) Iter(n int) IDIterator

func (*IntersectIterator) IterDiff

func (iter *IntersectIterator) IterDiff(n int) IDIterator

func (*IntersectIterator) JumpTo

func (iter *IntersectIterator) JumpTo(id ModelSortable) bool

func (*IntersectIterator) NextID

func (iter *IntersectIterator) NextID() ModelSortable

func (*IntersectIterator) Range

func (*IntersectIterator) Size

func (iter *IntersectIterator) Size() int

func (*IntersectIterator) SizeDiffs

func (iter *IntersectIterator) SizeDiffs() int

type IterColumner

type IterColumner interface {
	Key(i int) ModelSortable
	Len() int
}

IterColumner must be sorted by key in ascending order

type KV

type KV struct {
	K ModelSortable
	V ModelSortable // IdField in ModelTable.md
}

type MergeIterator

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

func NewMergeIterator

func NewMergeIterator(iterators ...IDIterator) *MergeIterator

func (*MergeIterator) Cardinality

func (iter *MergeIterator) Cardinality() int

func (*MergeIterator) Clone

func (iter *MergeIterator) Clone() IDIterator

func (*MergeIterator) HasNext

func (iter *MergeIterator) HasNext() bool

func (*MergeIterator) JumpTo

func (iter *MergeIterator) JumpTo(id ModelSortable) bool

func (*MergeIterator) NextID

func (iter *MergeIterator) NextID() ModelSortable

func (*MergeIterator) Range

func (iter *MergeIterator) Range() (l ModelSortable, r ModelSortable)

type ModelDescription

type ModelDescription struct {
	ModelType reflect.Type
	StoreName string

	IdField        *FieldDescription
	CreatedAtField *FieldDescription
	UpdatedAtField *FieldDescription
	DeletedAtField *FieldDescription

	Columns           []FieldDescription
	ColumnPtrs        []*FieldDescription
	ColumnByName      map[string]*FieldDescription //указатель
	ColumnByFieldName map[string]*FieldDescription
	ColumnByJsonName  map[string]*FieldDescription
}

Model description

func NewModelDescription

func NewModelDescription(modelType reflect.Type, storeName string) (*ModelDescription, error)

Создает новую модель и заполняет поля

func (ModelDescription) GetColumnByFieldName

func (md ModelDescription) GetColumnByFieldName(fieldName string) (*FieldDescription, error)

func (ModelDescription) GetColumnByJsonName

func (md ModelDescription) GetColumnByJsonName(jsonName string) (*FieldDescription, error)

func (ModelDescription) GetColumnsByFieldNames

func (md ModelDescription) GetColumnsByFieldNames(fieldNames ...string) (res []*FieldDescription)

func (ModelDescription) GetModelType

func (md ModelDescription) GetModelType() reflect.Type

func (ModelDescription) GetName

func (md ModelDescription) GetName() string

func (ModelDescription) GetStoredColumnNames

func (md ModelDescription) GetStoredColumnNames() (res []string)

func (ModelDescription) GetUniqName

func (md ModelDescription) GetUniqName() string

func (*ModelDescription) SearchField

func (md *ModelDescription) SearchField(f *FieldDescription) int

type ModelIndex

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

func NewModelIndex

func NewModelIndex(capacity int) *ModelIndex

func (*ModelIndex) Delete

func (mi *ModelIndex) Delete(kv KV)

func (*ModelIndex) DeleteAllForKey

func (mi *ModelIndex) DeleteAllForKey(kk ModelSortable)

func (*ModelIndex) Insert

func (mi *ModelIndex) Insert(kv KV)

func (*ModelIndex) Key

func (mi *ModelIndex) Key(i int) ModelSortable

IterColumner interface

func (*ModelIndex) Len

func (mi *ModelIndex) Len() int

type ModelObject

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

func NewModelObject

func NewModelObject(md *ModelDescription, sessionFrom ...ModelObject) ModelObject

func (ModelObject) Clear

func (mo ModelObject) Clear()

func (*ModelObject) Close

func (mo *ModelObject) Close()

func (ModelObject) CopyTo

func (mo ModelObject) CopyTo(dest *ModelObject)

func (ModelObject) DBData

func (mo ModelObject) DBData() (cols []string, vals []interface{})

func (ModelObject) Delete

func (mo ModelObject) Delete(fd *FieldDescription)

func (ModelObject) Field

func (mo ModelObject) Field(fd *FieldDescription) interface{}

func (ModelObject) FieldCount

func (mo ModelObject) FieldCount() int

func (*ModelObject) FromMap

func (mo *ModelObject) FromMap(data map[string]interface{}) error

keys = json names

func (*ModelObject) FromStruct

func (mo *ModelObject) FromStruct(src interface{}) error

func (ModelObject) GetColumnsByFieldNames

func (mo ModelObject) GetColumnsByFieldNames(fieldNames ...string) (res []*FieldDescription)

func (ModelObject) IDField

func (mo ModelObject) IDField() interface{}

func (ModelObject) MD

func (mo ModelObject) MD() *ModelDescription

func (ModelObject) MarshalJSON

func (mo ModelObject) MarshalJSON() ([]byte, error)

func (ModelObject) Prepare

func (mo ModelObject) Prepare() error

func (*ModelObject) RowScan

func (mo *ModelObject) RowScan(r sqlx.ColScanner, aliases ...string) error

RowScan scans a single sqlx.Row into the dest ModelObject. Columns which occur more than once in the result will overwrite each other! Only one table alias (or none) is supported

func (ModelObject) SetField

func (mo ModelObject) SetField(fd *FieldDescription, val interface{}) error

func (ModelObject) SetIDField

func (mo ModelObject) SetIDField(id interface{}) error

func (ModelObject) String

func (mo ModelObject) String() string

func (ModelObject) ToStruct

func (mo ModelObject) ToStruct(target interface{}) error

target is pointer to model struct

func (*ModelObject) UnmarshalJSON

func (mo *ModelObject) UnmarshalJSON(b []byte) error

func (ModelObject) Validate

func (mo ModelObject) Validate() error

func (ModelObject) Walk

func (mo ModelObject) Walk(f func(fd *FieldDescription, value interface{}))

type ModelSortable

type ModelSortable interface {
	ModelLess(ModelSortable) bool
	ModelEqual(ModelSortable) bool
}

type ModelTable

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

func NewModelTable

func NewModelTable(md *ModelDescription, capacity int) *ModelTable

func (*ModelTable) CreateIndex

func (mt *ModelTable) CreateIndex(fd *FieldDescription) *ModelIndex

func (*ModelTable) DeleteIndex

func (mt *ModelTable) DeleteIndex(fd *FieldDescription)

func (*ModelTable) HasIndex

func (mt *ModelTable) HasIndex(fd *FieldDescription) bool

func (*ModelTable) Key

func (mt *ModelTable) Key(i int) ModelSortable

IterColumner interface

func (*ModelTable) Len

func (mt *ModelTable) Len() int

func (*ModelTable) MarshalJSON

func (mt *ModelTable) MarshalJSON() ([]byte, error)

func (*ModelTable) Upsert

func (mt *ModelTable) Upsert(mo ModelObject) error

type NullType

type NullType struct{}
var Null NullType

func (*NullType) ConvertFrom

func (fnil *NullType) ConvertFrom(v interface{}) error

func (NullType) MarshalJSON

func (fnil NullType) MarshalJSON() ([]byte, error)

type Relation

type Relation struct {
	Type                RelationType
	ForeignKey          string
	ManyToManyTableName string
	Preload             bool
	Cascade             bool
}

func (*Relation) ParseTag

func (r *Relation) ParseTag(tag string) bool

func (Relation) String

func (r Relation) String() string

type RelationType

type RelationType int
const (
	RelationTypeNotRelation RelationType = iota
	RelationTypeHasMany
	RelationTypeManyToMany
	RelationTypeBelongsTo
	RelationTypeHasOne
)

type Storable

type Storable interface {
	StoreName() string
}

type String

type String string

func (String) ModelEqual

func (u String) ModelEqual(ms ModelSortable) bool

func (String) ModelLess

func (u String) ModelLess(ms ModelSortable) bool

ModelSortable interface

type UUIDv4

type UUIDv4 struct {
	uuid.UUID
}

func FromString

func FromString(s string) (UUIDv4, error)

func NewV4

func NewV4() UUIDv4

func (*UUIDv4) ConvertFrom

func (u *UUIDv4) ConvertFrom(v interface{}) error

store.Converter interface, u must contain zero value before call

func (*UUIDv4) GobDecode

func (u *UUIDv4) GobDecode(data []byte) error

func (UUIDv4) GobEncode

func (u UUIDv4) GobEncode() ([]byte, error)

func (UUIDv4) IsZero

func (u UUIDv4) IsZero() bool

func (UUIDv4) ModelEqual

func (u UUIDv4) ModelEqual(ms ModelSortable) bool

func (UUIDv4) ModelLess

func (u UUIDv4) ModelLess(ms ModelSortable) bool

ModelSortable interface

func (*UUIDv4) Scan

func (u *UUIDv4) Scan(src interface{}) error

func (UUIDv4) String

func (u UUIDv4) String() string

func (UUIDv4) Value

func (u UUIDv4) Value() (driver.Value, error)

type ValidationErrorDesc

type ValidationErrorDesc struct {
	ModelID   interface{} `json:"modelId,omitempty"`
	Field     string      `json:"field"`
	Namespace string      `json:"namespace"`
	Validator string      `json:"validator"`
	Param     string      `json:"param"`
	Message   string      `json:"message"`
}

Jump to

Keyboard shortcuts

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