entity

package
v0.0.0-...-75e7317 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const FieldCreatedAt = "created_at"
View Source
const FieldDeletedAt = "deleted_at"
View Source
const FieldID = "id"
View Source
const FieldUpdatedAt = "updated_at"

Variables

This section is empty.

Functions

func BindEntity

func BindEntity[T any](e *Entity) (result T, err error)

BindEntity binds the fields of the given Entity to a target struct value.

func UnmarshalJSONValue

func UnmarshalJSONValue(
	data []byte,
	valueData []byte,
	dataType jsonparser.ValueType,
	offset int,
) (any, error)

UnmarshalJSONValue converts json bytes to a Go value.

Types

type Entity

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

func New

func New(ids ...uint64) *Entity

New creates a new entity.

func NewEntityFromJSON

func NewEntityFromJSON(jsonData string) (*Entity, error)

NewEntityFromJSON creates a new entity from a JSON string.

func NewEntityFromMap

func NewEntityFromMap(data map[string]any) *Entity

NewEntityFromMap creates a new entity from a map.

func (*Entity) Data

func (e *Entity) Data() *orderedmap.OrderedMap[string, any]

func (*Entity) Delete

func (e *Entity) Delete(name string) *Entity

Delete removes a value from the entity.

func (*Entity) Empty

func (e *Entity) Empty() bool

Empty returns true if the entity is empty.

func (*Entity) First

func (e *Entity) First() *orderedmap.Pair[string, any]

First returns the oldest key/value pair in the entity.

func (*Entity) Get

func (e *Entity) Get(name string, defaultValues ...any) any

Get returns a value from the entity.

func (*Entity) GetString

func (e *Entity) GetString(name string, defaultValues ...string) string

GetString returns a string value from the entity.

func (*Entity) GetUint64

func (e *Entity) GetUint64(name string, optional bool) (uint64Value uint64, err error)

GetUint64 returns the foreign key value (uint64) from the entity.

func (*Entity) ID

func (e *Entity) ID() uint64

ID returns the ID of the entity.

func (*Entity) Keys

func (e *Entity) Keys() []string

Keys returns the keys of the entity.

func (*Entity) MarshalJSON

func (e *Entity) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Entity) Set

func (e *Entity) Set(name string, value any) *Entity

Set sets a value in the entity.

func (*Entity) SetID

func (e *Entity) SetID(value any) error

SetID sets the ID of the entity. if the value is not a valid ID, returns the error.

func (*Entity) String

func (e *Entity) String() string

String returns the string representation of the entity.

func (*Entity) ToJSON

func (e *Entity) ToJSON() (string, error)

ToJSON converts the entity to a JSON string.

func (*Entity) ToMap

func (e *Entity) ToMap() map[string]any

ToMap converts the entity to a map.

func (*Entity) UnmarshalJSON

func (e *Entity) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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