schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Name = "schema"
)

Variables

This section is empty.

Functions

func Mapify

func Mapify(d bson.D) bson.M

Map creates a map from the elements of the D. It makes additional process for arrays

func SetValue

func SetValue(m bson.M, key []string, v interface{}) error

func ToBsonD

func ToBsonD(m bson.M) bson.D

func Validate

func Validate(ctx context.Context, obj bson.D, fields map[string]CollectionField, denyUnknownFields, isUpdate bool) error

Validate checks datatype aganst CollectionField It validates either Insert or Update TODO: remove the .Map()?

func WalkCollectionFields

func WalkCollectionFields(fields map[string]CollectionField, fn WalkCollectionFieldsFunc) error

Types

type BSONType

type BSONType string
const (
	// BSON types, not all of them supported yet.
	INT             BSONType = "int"
	INT_ARRAY       BSONType = "[]int"
	LONG            BSONType = "long"
	LONG_ARRAY      BSONType = "[]long"
	DOUBLE          BSONType = "double"
	DOUBLE_ARRAY    BSONType = "[]double"
	STRING          BSONType = "string"
	STRING_ARRAY    BSONType = "[]string"
	OBJECT          BSONType = "object"
	OBJECT_ARRAY    BSONType = "[]object"
	BIN_DATA        BSONType = "binData"
	BIN_DATA_ARRAY  BSONType = "[]binData"
	OBJECT_ID       BSONType = "objectID"
	OBJECT_ID_ARRAY BSONType = "[]objectID"
	BOOL            BSONType = "bool"
	BOOL_ARRAY      BSONType = "[]bool"
	DATE            BSONType = "date"
	DATE_ARRAY      BSONType = "[]date"
	NULL            BSONType = "null"
	REGEX           BSONType = "regex"
	DECIMAL128      BSONType = "decimal"

	SKIP_SCHEMA_ANNOTATION = "skipSchema"
)

type ClusterSchema

type ClusterSchema struct {
	MongosEndpoint       string              `json:"mongosEndpoint"`
	Annotations          map[string]string   `json:"annotations,omitempty"`
	Databases            map[string]Database `json:"dbs"`
	DenyUnknownDatabases bool                `json:"denyUnknownDatabases,omitempty"`
}

func (*ClusterSchema) UnmarshalJSON

func (s *ClusterSchema) UnmarshalJSON(data []byte) error

func (*ClusterSchema) ValidateInsert

func (s *ClusterSchema) ValidateInsert(ctx context.Context, database, collection string, obj bson.D) error

ValidateInsert will validate the schema of the passed in object.

func (*ClusterSchema) ValidateUpdate

func (s *ClusterSchema) ValidateUpdate(ctx context.Context, database, collection string, obj bson.D, upsert bool) error

ValidateUpdate will validate the schema of the passed in object.

type Collection

type Collection struct {
	Annotations map[string]string `json:"annotations,omitempty"`
	// All the columns in this table
	Fields map[string]CollectionField `json:"fields"`
	// Whether we should strictly enforce fields or allow others
	DenyUnknownFields bool `json:"denyUnknownFields,omitempty"`
	// Whether we should enforce schema check for this collection
	EnforceSchema bool `json:"enforceSchema,omitempty"`
}

func (*Collection) GetField

func (c *Collection) GetField(names ...string) *CollectionField

func (*Collection) ValidateInsert

func (c *Collection) ValidateInsert(ctx context.Context, obj bson.D) error

ValidateInsert will validate the schema of the passed in object.

func (*Collection) ValidateUpdate

func (c *Collection) ValidateUpdate(ctx context.Context, obj bson.D, upsert bool) error

ValidateUpdate will validate the schema of the passed in object.

type CollectionField

type CollectionField struct {
	Name string   `json:"-"`
	Type BSONType `json:"type"`

	Annotations map[string]string `json:"annotations,omitempty"`

	// Various configuration options
	Required bool `json:"required,omitempty"`

	// Field is a array type
	IsArray bool

	// Optional subfields
	SubFields map[string]CollectionField `json:"subfields,omitempty"`
	// contains filtered or unexported fields
}

func (*CollectionField) Validate

func (c *CollectionField) Validate(ctx context.Context, v interface{}, denyUnknownFields, isUpdate bool) error

ValidateInsert will validate the schema of the passed in object.

func (*CollectionField) ValidateElement

func (c *CollectionField) ValidateElement(ctx context.Context, d interface{}, validateType BSONType) error

Validate elements type inside an array

type Database

type Database struct {
	Annotations            map[string]string     `json:"annotations,omitempty"`
	Collections            map[string]Collection `json:"collections"`
	DenyUnknownCollections bool                  `json:"denyUnknownCollections,omitempty"`
}

func (*Database) ValidateInsert

func (d *Database) ValidateInsert(ctx context.Context, collection string, obj bson.D) error

ValidateInsert will validate the schema of the passed in object.

func (*Database) ValidateUpdate

func (d *Database) ValidateUpdate(ctx context.Context, collection string, obj bson.D, upsert bool) error

ValidateUpdate will validate the schema of the passed in object.

type SchemaLoader

type SchemaLoader interface {
	// Load returns a bool (whether something was loaded) + error
	Load(ctx context.Context, glob string) error
	// Querier returns a querier of the current loaded config. The
	// returned querier must provide a consistent view over the data
	// (this way we get consistent schema enforcement throughout
	// all calls in a single request)
	Querier() SchemaQuerier
}

type SchemaPlugin

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

This is a plugin that handles sending the request to the acutual downstream mongo

func (*SchemaPlugin) Configure

func (p *SchemaPlugin) Configure(d bson.D) error

Configure configures this plugin with the given configuration object. Returns an error if the configuration is invalid for the plugin.

func (*SchemaPlugin) GetSchema

func (p *SchemaPlugin) GetSchema() *ClusterSchema

func (*SchemaPlugin) LoadSchema

func (p *SchemaPlugin) LoadSchema() (err error)

func (*SchemaPlugin) Name

func (p *SchemaPlugin) Name() string

func (*SchemaPlugin) Process

func (p *SchemaPlugin) Process(ctx context.Context, r *plugins.Request, next plugins.PipelineFunc) (bson.D, error)

Process is the function executed when a message is called in the pipeline.

type SchemaPluginConfig

type SchemaPluginConfig struct {
	// SchemaPath is the path on disk to the schema file to load + watch for changes
	SchemaPath string `bson:"schemaPath"`
}

type SchemaQuerier

type SchemaQuerier interface {
	SchemaValidator
}

type SchemaValidator

type SchemaValidator interface {
	// ValidateInsert will validate the schema of the passed in object.
	ValidateInsert(ctx context.Context, database, collection string, obj bson.D) error
	// ValidateUpdate will validate the schema of the passed in object.
	ValidateUpdate(ctx context.Context, database, collection string, obj bson.D) error
}

type WalkCollectionFieldsFunc

type WalkCollectionFieldsFunc func(string, *CollectionField) error

Jump to

Keyboard shortcuts

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