entity

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Copyright 2022. Motty Cohen

Entity interface and base entity for all persistent model entities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EntityIndex

func EntityIndex(entity Entity, tenantId string) string

*

  • Extract table or index name from entity.TABLE()

func NewGuid

func NewGuid() string

*

  • Generate new Global Unique Identifier

func NewId

func NewId() string

region Entity Ids --------------------------------------------------------------------------------------------------- *

  • Generate new id based on nanoId (faster and smaller than GUID)

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

*

  • Base structure for 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 {
	// Return the entity unique Id
	ID() string

	// Return the entity table name (for sharded entities, table name include the suffix of the tenant id)
	TABLE() string

	// Get entity name
	NAME() string

	// Get entity shard key (tenant id)
	KEY() string
}

region Entity Interface --------------------------------------------------------------------------------------------- *

  • Mark all concrete DB entities

type EntityAction

type EntityAction int
const (
	AddEntity    EntityAction = 1
	UpdateEntity EntityAction = 2
	DeleteEntity EntityAction = 3
)

type EntityFactory

type EntityFactory func() Entity

Factory method signature for Entity

type Json

type Json map[string]any

Represent arbitrary JSON fields collection

type JsonDoc

type JsonDoc struct {
	Id   string
	Data string
}

Json document to store in Document object store (Postgres, ElasticSearch, Couchbase ...)

type Timestamp

type Timestamp int64

Epoch milliseconds Timestamp

func EpochNowMillis

func EpochNowMillis(delta int64) Timestamp

Return current time as Epoch time milliseconds with delta in millis

func Now

func Now() Timestamp

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