Documentation ¶
Overview ¶
Package entity Entity interface and base entity for all persistent model entities
Index ¶
- func EntityIndex(entity Entity, tenantId string) string
- func GUID() string
- func ID() string
- func IDN() string
- func JsonUnmarshal(data Json, v any) error
- func Marshal(v any) ([]byte, error)
- func NanoID() string
- func ShortID(delta ...int) string
- func ShortIDN(delta ...int) string
- func Unmarshal(data []byte, v any) error
- type BaseEntity
- type BaseEntityEx
- type Entities
- type Entity
- type EntityAction
- type EntityFactory
- type Json
- type JsonDoc
- type SimpleEntity
- type TimeDataPoint
- type TimeFrame
- type TimeSeries
- type Timestamp
- type Tuple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EntityIndex ¶
EntityIndex extract table or index name from entity.TABLE()
func ID ¶ added in v1.1.2
func ID() string
ID return a long string (alphanumeric) based on Epoch micro-seconds in base 36
func IDN ¶ added in v1.2.21
func IDN() string
IDN return a long string (digits only) based on Epoch micro-seconds
func JsonUnmarshal ¶ added in v1.2.105
JsonUnmarshal convert map of string->any to entity
func NanoID ¶ added in v1.1.2
func NanoID() string
NanoID return a long string (6 characters) based on go-nanoid project (smaller and faster than GUID)
func ShortID ¶ added in v1.1.2
ShortID return a short string (6 characters alphanumeric) based on epoch seconds in base 36
Types ¶
type BaseEntity ¶
type BaseEntity struct { Id string `json:"id"` // Unique object Id CreatedOn Timestamp `json:"createdOn"` // When the object was created [Epoch milliseconds Timestamp] UpdatedOn Timestamp `json:"updatedOn"` // When the object was last updated [Epoch milliseconds Timestamp] }
BaseEntity is a base structure for any concrete Entity
func (*BaseEntity) ID ¶
func (e *BaseEntity) ID() string
func (*BaseEntity) KEY ¶
func (e *BaseEntity) KEY() string
func (*BaseEntity) NAME ¶
func (e *BaseEntity) NAME() string
func (*BaseEntity) TABLE ¶
func (e *BaseEntity) TABLE() string
type BaseEntityEx ¶ added in v1.2.116
type BaseEntityEx struct { Id string `json:"id"` // Unique object Id CreatedOn Timestamp `json:"createdOn"` // When the object was created [Epoch milliseconds Timestamp] UpdatedOn Timestamp `json:"updatedOn"` // When the object was last updated [Epoch milliseconds Timestamp] Props Json `json:"props"` // List of custom properties }
BaseEntityEx is an extended base Entity with custom attributes
func (*BaseEntityEx) ID ¶ added in v1.2.116
func (e *BaseEntityEx) ID() string
func (*BaseEntityEx) KEY ¶ added in v1.2.116
func (e *BaseEntityEx) KEY() string
func (*BaseEntityEx) NAME ¶ added in v1.2.116
func (e *BaseEntityEx) NAME() string
func (*BaseEntityEx) TABLE ¶ added in v1.2.116
func (e *BaseEntityEx) TABLE() string
type Entities ¶ added in v1.2.104
type Entities[T any] struct { Values []T `json:"values"` // entity list }
Entities is a primitive/complex type array expressed as an Entity
type Entity ¶
type Entity interface { // ID return the entity unique Id ID() string // TABLE return the entity table name (for sharded entities, table name include the suffix of the tenant id) TABLE() string // NAME return the entity name NAME() string // KEY return the entity sharding key (tenant/account id) based on one of the entity's attributes KEY() string }
Entity is a marker interface for all serialized domain model entities with identity
func NewBaseEntity ¶ added in v1.2.41
func NewBaseEntity() Entity
func NewBaseEntityEx ¶ added in v1.2.116
func NewBaseEntityEx() Entity
func NewEntities ¶ added in v1.2.104
func NewSimpleEntity ¶ added in v1.2.41
type EntityAction ¶
type EntityAction int
const ( AddEntity EntityAction = 1 UpdateEntity EntityAction = 2 DeleteEntity EntityAction = 3 )
type EntityFactory ¶
type EntityFactory func() Entity
EntityFactory is the factory method signature for Entity
type Json ¶
Json Represent arbitrary JSON fields collection
func JsonMarshal ¶ added in v1.2.105
JsonMarshal convert any type to a map of string->any
type JsonDoc ¶
JsonDoc is a Json document to store in Document object store (Postgres, ElasticSearch, Couchbase ...)
type SimpleEntity ¶ added in v1.2.41
type SimpleEntity[T any] struct { Value T `json:"value"` // entity value }
SimpleEntity is a primitive type expressed as an Entity
func (*SimpleEntity[T]) ID ¶ added in v1.2.41
func (e *SimpleEntity[T]) ID() string
func (*SimpleEntity[T]) KEY ¶ added in v1.2.41
func (e *SimpleEntity[T]) KEY() string
func (*SimpleEntity[T]) NAME ¶ added in v1.2.41
func (e *SimpleEntity[T]) NAME() string
func (*SimpleEntity[T]) TABLE ¶ added in v1.2.41
func (e *SimpleEntity[T]) TABLE() string
type TimeDataPoint ¶ added in v1.2.35
type TimeDataPoint[V any] struct { Timestamp Timestamp `json:"timestamp"` // Timestamp Value V `json:"value"` // Generic value }
TimeDataPoint model represents a generic datapoint in time
func NewTimeDataPoint ¶ added in v1.2.35
func NewTimeDataPoint[V any](ts Timestamp, value V) TimeDataPoint[V]
NewTimeDataPoint return new instance of the datapoint
func (*TimeDataPoint[V]) String ¶ added in v1.2.35
func (tf *TimeDataPoint[V]) String(format string) string
String convert Epoch milliseconds timestamp to readable string
type TimeFrame ¶ added in v1.2.26
type TimeFrame struct { From Timestamp `json:"from"` // From Timestamp To Timestamp `json:"to"` // To Timestamp }
TimeFrame represents a slot in time
func GetTimeFrame ¶ added in v1.2.26
GetTimeFrame return new time slot using start and duration
func NewTimeFrame ¶ added in v1.2.26
NewTimeFrame return new time slot using start and end time
type TimeSeries ¶ added in v1.2.99
type TimeSeries[T any] struct { Name string `json:"name"` // Name of the time series Range TimeFrame `json:"range"` // Range of the series (from ... to) Values []TimeDataPoint[T] `json:"values"` // Series data points }
TimeSeries is a set of data points over time
func (*TimeSeries[T]) ID ¶ added in v1.2.99
func (ts *TimeSeries[T]) ID() string
func (*TimeSeries[T]) KEY ¶ added in v1.2.99
func (ts *TimeSeries[T]) KEY() string
func (*TimeSeries[T]) NAME ¶ added in v1.2.99
func (ts *TimeSeries[T]) NAME() string
func (*TimeSeries[T]) TABLE ¶ added in v1.2.99
func (ts *TimeSeries[T]) TABLE() string
type Timestamp ¶
type Timestamp int64
Timestamp represents Epoch milliseconds timestamp
func EpochNowMillis ¶
EpochNowMillis return current time as Epoch time milliseconds with delta in millis
func Now ¶
func Now() Timestamp
Now return current time as Epoch time milliseconds with delta in millis
func (*Timestamp) LocalString ¶ added in v1.2.15
LocalString convert Epoch milliseconds timestamp with timezone (IANA) to readable string