schema_interpreter

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Copyright (c) 2023 the go-mongr8 Authors and Contributors [@see Authors file]

Licensed under the MIT License (https://opensource.org/licenses/MIT)

Copyright (c) 2023 the go-mongr8 Authors and Contributors [@see Authors file]

Licensed under the MIT License (https://opensource.org/licenses/MIT)

Copyright (c) 2023 the go-mongr8 Authors and Contributors [@see Authors file]

Licensed under the MIT License (https://opensource.org/licenses/MIT)

Copyright (c) 2023 the go-mongr8 Authors and Contributors [@see Authors file]

Licensed under the MIT License (https://opensource.org/licenses/MIT)

Copyright (c) 2023 the go-mongr8 Authors and Contributors [@see Authors file]

Licensed under the MIT License (https://opensource.org/licenses/MIT)

Copyright (c) 2023 the go-mongr8 Authors and Contributors [@see Authors file]

Licensed under the MIT License (https://opensource.org/licenses/MIT)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToLiteral

func AnyToLiteral(value interface{}) string

convert any value to literal, this function can be called any where

func ConvertValueTypeToRealType

func ConvertValueTypeToRealType(value interface{}) interface{}

ConvertValueTypeToRealType return value reversal of ValueType(d) structure as defined in migration/translator/dictionary TODO: find better approach in the future as the ValueType was intended because of to many type conversions needed

Types

type Action

type Action struct {
	// ActionIf
	ActionKey string
	// sub actions should be execute respectively
	SubActions []SubAction
}

Action holds operations that will be performed in a collection

func (Action) GetLiteralInstance

func (a Action) GetLiteralInstance(prefix string, isArrayItem bool) string

type SubAction

type SubAction struct {
	SubActionIf
	// could be the name of collection, index, field, or etc
	Type SubActionType
	// schema changed in this action
	ActionSchema SubActionSchema
	// contains filtered or unexported fields
}

SubAction handles atomic action as part of main Action

func SubActionConvertField

func SubActionConvertField(schema SubActionSchema) *SubAction

func SubActionCreateCollection

func SubActionCreateCollection(schema SubActionSchema) *SubAction

func SubActionCreateField

func SubActionCreateField(schema SubActionSchema) *SubAction

func SubActionCreateIndex

func SubActionCreateIndex(schema SubActionSchema) *SubAction

func SubActionDropCollection

func SubActionDropCollection(schema SubActionSchema) *SubAction

func SubActionDropField

func SubActionDropField(schema SubActionSchema) *SubAction

func SubActionDropIndex

func SubActionDropIndex(schema SubActionSchema) *SubAction

func (SubAction) GetFieldsBsonD

func (sa SubAction) GetFieldsBsonD() bson.D

func (SubAction) GetFieldsBsonM

func (sa SubAction) GetFieldsBsonM() bson.M

func (SubAction) GetIndexesBsonD

func (sa SubAction) GetIndexesBsonD() []dt.Pair[string, dt.Pair[bson.D, bson.D]]

func (SubAction) GetIndexesBsonM

func (sa SubAction) GetIndexesBsonM() []dt.Pair[string, dt.Pair[bson.M, bson.M]]

func (SubAction) GetLiteralInstance

func (sa SubAction) GetLiteralInstance(prefix string, isArrayItem bool) string

func (SubAction) IsUp

func (sa SubAction) IsUp() bool

type SubActionIf

type SubActionIf interface {
	// flag whether current sub action is Up or Down
	IsUp() bool
	// this will return pairs of index and rule
	GetIndexesBsonD() []dt.Pair[string, dt.Pair[bson.D, bson.D]]
	GetIndexesBsonM() []dt.Pair[string, dt.Pair[bson.M, bson.M]]
	// this will return whole field schema in the collection
	GetFieldsBsonD() bson.D
	GetFieldsBsonM() bson.M
}

type SubActionSchema

type SubActionSchema struct {
	// Collection must always be defined
	// if Fields and Indexes are not defined, then it must be
	// related to collection option, i.e: Create Collection
	Collection collection.Metadata
	Fields     []collection.Field
	Indexes    []collection.Index
	// field type for conversion
	// we're expecting only a single field conversion
	// each sub action
	FieldConvertFrom *field.FieldType
}

SubActionSchema holds what are being changed/adjusted in the current SubAction this data will be used to compare the generated migration files schema with the higher level user-defined schema in /mongr8/collection

func (SubActionSchema) GetLiteralInstance

func (sas SubActionSchema) GetLiteralInstance(prefix string, isArrayItem bool) string

type SubActionType

type SubActionType string
const (
	SubActionTypeCreateCollection SubActionType = "SubActionTypeCreateCollection"
	SubActionTypeCreateIndex      SubActionType = "SubActionTypeCreateIndex"
	SubActionTypeCreateField      SubActionType = "SubActionTypeCreateField"
	SubActionTypeConvertField     SubActionType = "SubActionTypeConvertField"
	SubActionTypeDropCollection   SubActionType = "SubActionTypeDropCollection"
	SubActionTypeDropIndex        SubActionType = "SubActionTypeDropIndex"
	SubActionTypeDropField        SubActionType = "SubActionTypeDropField"
)

make sure constant name is exactly same as it's value

func (SubActionType) ToString

func (sat SubActionType) ToString() string

Jump to

Keyboard shortcuts

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