load

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package load is the interface for loading an mongox/schema package into a Go program.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalSchema

func MarshalSchema(schema mongox.Interface) (b []byte, err error)

MarshalSchema encodes the mongox.Schema interface into a JSON that can be decoded into the Schema objects declared above.

Types

type Config

type Config struct {
	// Path is the path for the schema package.
	Path string
	// Names are the schema names to load. Empty means all schemas in the directory.
	Names []string
	// BuildFlags are forwarded to the package.Config when
	// loading the schema package.
	BuildFlags []string
}

Config holds the configuration for loading an mongox/schema package.

func (*Config) Load

func (c *Config) Load() (*SchemaSpec, error)

Load loads the schemas package and build the Go plugin with this info.

type Field

type Field struct {
	Tag       string          `json:"tag,omitempty"`
	Name      string          `json:"name,omitempty"`
	FieldType types.MongoType `json:"type,omitempty"`
	Optional  bool            `json:"optional,omitempty"`
	EmbedData []*Field        `json:"embed_data,omitempty"`
	ArrayType types.MongoType `json:"array_type,omitempty"`
}

Field represents an ent.Field that was loaded from a complied user package.

func NewField

func NewField(fd *field.Descriptor) (*Field, error)

NewField creates a loaded field from field descriptor.

type Index

type Index struct {
	StorageKey string           `json:"storage_key,omitempty"`
	Unique     bool             `json:"unique,omitempty"`
	Background bool             `json:"background,omitempty"`
	Sparse     bool             `json:"sparse,omitempty"`
	Expire     time.Duration    `json:"expire,omitempty"`
	Keys       []types.MapEntry `json:"keys,omitempty"`
}

Index represents an ent.Index that was loaded from a complied user package.

func NewIndex

func NewIndex(idx *index.Descriptor) *Index

NewIndex creates an loaded index from index descriptor.

type Schema

type Schema struct {
	Name    string   `json:"name,omitempty"`
	Fields  []*Field `json:"fields,omitempty"`
	Indexes []*Index `json:"indexes,omitempty"`
}

Schema represents an ent.Schema that was loaded from a complied user package.

func UnmarshalSchema

func UnmarshalSchema(buf []byte) (*Schema, error)

UnmarshalSchema decodes the given buffer to a loaded schema.

func (*Schema) FieldNames

func (s *Schema) FieldNames() []string

FieldNames 获取路径

func (*Schema) PathList

func (s *Schema) PathList() []string

PathList 获取路径

func (*Schema) SubObject

func (s *Schema) SubObject() []*SubObject

SubObject 获取对象数组

type SchemaSpec

type SchemaSpec struct {
	// Schemas defines the loaded schema descriptors.
	Schemas []*Schema

	// PkgPath is the package path of the loaded
	// mongox.Schema package.
	PkgPath string

	// Module defines the module information for
	// the user schema package if exists.
	Module *packages.Module
}

A SchemaSpec holds a serializable version of an mongox.Schema and its Go package and module information.

type SubObject

type SubObject struct {
	Name   string
	Fields []*Field
}

Jump to

Keyboard shortcuts

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