marshal

package
v0.0.0-...-f9581dc Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const StatusOK = "OK"

Variables

View Source
var (
	ErrNotStruct    = errors.New("data is not struct")
	ErrNotValidFunc = errors.New("invalid function")
)

Smart Marshal Errors

Functions

func SmartMarshal

func SmartMarshal[I any](inputfunc interface{}, data I) (output interface{}, err error)

Smartmarshal can be used with all DB methods with generics and type safety. This handles errors and can use any struct tag with `BaseModel` type. Warning: "ID" field is case sensitive and expect string. Upon failure, the following will happen 1. If there are some ID on struct it will fill the table with the ID 2. If there are struct tags of the type `Basemodel`, it will use those values instead 3. If everything above fails or the IDs do not exist, SmartUnmarshal will use the struct name as the table name.

func SmartUnmarshal

func SmartUnmarshal[I any](respond interface{}, out *I) error

SmartUnmarshal using generics for return desired type. Supports both raw and normal queries.

func Unmarshal

func Unmarshal(data, v interface{}) (err error)

Unmarshal loads a SurrealDB response into a struct.

func UnmarshalRaw

func UnmarshalRaw[I any](rawData interface{}, v *[]RawQuery[I]) (err error)

UnmarshalRaw loads a raw SurrealQL response returned by Query into a struct. Queries that return with results will return ok = true, and queries that return with no results will return ok = false.

Types

type Basemodel

type Basemodel struct{}

Used for define table name, it has no value.

type RawQuery

type RawQuery[I any] struct {
	Status string `json:"status"`
	Time   string `json:"time"`
	Result I      `json:"result"`
	Detail string `json:"detail"`
}

Used for RawQuery Unmarshaling

Jump to

Keyboard shortcuts

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