entity

package
v1.2.69 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 11 Imported by: 12

Documentation

Overview

Package entity Entity interface and base entity for all persistent model entities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryMarshal added in v1.2.67

func BinaryMarshal(v any) ([]byte, error)

BinaryMarshal returns the best wire format encoding of v. If v implements encoding.BinaryMarshaler it will return the binary format, otherwise it will apply JSON encoding

func BinaryUnmarshal added in v1.2.67

func BinaryUnmarshal(data []byte, v any) error

BinaryUnmarshal will try to unmarshal binary data if v implements encoding.BinaryUnmarshaler, otherwise it will use JSON unmarshal

func EntityIndex

func EntityIndex(entity Entity, tenantId string) string

EntityIndex extract table or index name from entity.TABLE()

func GUID added in v1.1.2

func GUID() string

GUID generate new Global Unique Identifier

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 Marshal added in v1.2.55

func Marshal(v any) ([]byte, error)

Marshal returns the JSON encoding of v

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

func ShortID(delta ...int) string

ShortID return a short string (6 characters alphanumeric) based on epoch seconds in base 36

func ShortIDN added in v1.2.21

func ShortIDN(delta ...int) string

ShortIDN return a short string (digits only) based on epoch seconds

func Unmarshal added in v1.2.55

func Unmarshal(data []byte, v any) error

Unmarshal returns the struct from JSON byte array

func UnmarshalFromString added in v1.2.55

func UnmarshalFromString(data string, v any) error

UnmarshalFromString returns the struct from JSON string

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 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 NewSimpleEntity added in v1.2.41

func NewSimpleEntity[T any]() Entity

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

type Json map[string]any

Json Represent arbitrary JSON fields collection

type JsonDoc

type JsonDoc struct {
	Id   string
	Data string
}

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

func GetTimeFrame(from Timestamp, duration time.Duration) TimeFrame

GetTimeFrame return new time slot using start and duration

func NewTimeFrame added in v1.2.26

func NewTimeFrame(from, to Timestamp) TimeFrame

NewTimeFrame return new time slot using start and end time

func (*TimeFrame) Duration added in v1.2.26

func (tf *TimeFrame) Duration() time.Duration

Duration of the timeframe

func (*TimeFrame) String added in v1.2.26

func (tf *TimeFrame) String(format string) string

String convert Epoch milliseconds timestamp to readable string

type Timestamp

type Timestamp int64

Timestamp represents Epoch milliseconds timestamp

func EpochNowMillis

func EpochNowMillis(delta int64) Timestamp

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) Add added in v1.2.15

func (ts *Timestamp) Add(delta time.Duration) Timestamp

Add time and return a new timestamp

func (*Timestamp) LocalString added in v1.2.15

func (ts *Timestamp) LocalString(format string, tz string) string

LocalString convert Epoch milliseconds timestamp with timezone (IANA) to readable string

func (*Timestamp) String added in v1.2.15

func (ts *Timestamp) String(format string) string

String convert Epoch milliseconds timestamp to readable string

func (*Timestamp) Time added in v1.2.15

func (ts *Timestamp) Time() (result time.Time)

Time returns the Go primitive time.Time object

type Tuple added in v1.2.35

type Tuple[K, V any] struct {
	Key   K `json:"key"`   // Tuple key
	Value V `json:"value"` // Tuple value
}

Tuple model represents a generic key-value pair

Jump to

Keyboard shortcuts

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