model

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DereferencedType

func DereferencedType(t reflect.Type) reflect.Type

DereferencedType returns the innermost type that is not reflect.Interface or reflect.Ptr.

Types

type Attribute

type Attribute struct {
	// Field is the original struct field that was parsed.
	Field reflect.StructField
	// Name is the first tag value in the `dynamodbav` struct tag.
	Name string
	// DataType describes the type of data that this attribute stores.
	DataType DataType
	// OmitEmpty is true only if the `dynamodbav` struct tag also includes `omitempty`.
	OmitEmpty bool
	// UnixTime is true only if the `dynamodbav` struct tag also includes `unixtime`.
	UnixTime bool
}

Attribute contains metadata about a reflect.StructField that represents a DynamoDB attribute.

func (*Attribute) EncodeKey

func (a *Attribute) EncodeKey(value interface{}) (types.AttributeValue, error)

EncodeKey encodes the given value as a DynamoDB key attribute value (can only be S, N, or B type).

func (*Attribute) Get

func (a *Attribute) Get(value reflect.Value) (reflect.Value, error)

Get returns the reflected value from the given struct value.

type DataType

type DataType int

DataType models DynamoDB data type.

const (
	DataTypeUnknown DataType = iota
	DataTypeS
	DataTypeN
	DataTypeB
)

type Model

type Model struct {
	// StructType is the type of the struct from which the Model instance was parsed.
	StructType   reflect.Type
	TableName    *string
	HashKey      *Attribute
	SortKey      *Attribute
	Version      *Attribute
	CreatedTime  *Attribute
	ModifiedTime *Attribute
}

Model contain metadata about attributes that have been parsed successfully from struct tags `dynamodbav`.

func ParseFromStruct

func ParseFromStruct(v interface{}) (*Model, error)

ParseFromStruct parses the struct tags given by an instance of the struct.

Returns an error if there are validation issues.

func ParseFromType

func ParseFromType(t reflect.Type) (*Model, error)

ParseFromType parses the struct tags given by its type.

Returns an error if there are validation issues.

Jump to

Keyboard shortcuts

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