entity

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 6 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 (10 characters) based on Epoch micro-seconds in base 36

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) based on epoch seconds in base 36

Types

type BaseEntity

type BaseEntity struct {
	Id        string    `json:"id"`        // Unique object Id
	Key       string    `json:"key"`       // Shard (tenant) key
	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)
	KEY() string
}

Entity is a marker interface for all serialized domain model entities with identity

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 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

Jump to

Keyboard shortcuts

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