schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package schema implements the DataModel management.

Index

Constants

View Source
const (
	TextField     = "text"
	VarcharField  = "string"
	IntField      = "int"
	FloatField    = "float"
	DoubleField   = "double"
	BooleanField  = "boolean"
	DatetimeField = "datetime"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataModel

type DataModel struct {
	ID          string     `validate:"required" json:"id"`
	Name        string     `validate:"required" json:"name"`
	TableName   string     `json:"tableName"`
	Properties  []Property `validate:"required" json:"properties"`
	PrimaryKeys []string   `validate:"required" json:"-"`
}

DataModel is a notation for describing data or information. Including

Structure of the data

Operations on the data. Users are generally allowed to perform a limited set of actions on the data, e.g., a property is readonly, while another property (think about the password field of DataModel User) is write-only

Constraints on the data. Describe limitations on what the data can be.

func ValidateJSON

func ValidateJSON(target string) (*DataModel, error)

ValidateJSON checks if the input json string is a valid DataModel

type Property

type Property struct {
	// ID is used to identify this property, which will be used as the name of this column
	// should follow pattern ^[a-z_][a-z0-9_]*$
	ID string `json:"id" validate:"required"`
	// Name is used for business observers
	Name string `json:"name" validate:"required"`
	// Type can be any of "string", "text", "number", "boolean", "date"
	// string must have a max length, while text does not require this
	// string => VARCHAR
	// text => TEXT
	Type     string                 `json:"type" validate:"required"`
	Options  map[string]interface{} `json:"options"`
	Comments string                 `json:"comments"`
	Required bool                   `json:"required" validate:"required"`
}

Property defines all necessary information of one field

func (*Property) GetOptionsForVarCharField

func (p *Property) GetOptionsForVarCharField() (*VarCharOptions, error)

type VarCharOptions

type VarCharOptions struct {
	MaxLength int `json:"maxLength"`
}

Jump to

Keyboard shortcuts

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