schema

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 2 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"`
	Identifier  string     `validate:"required" json:"identifier"`
	Name        string     `validate:"required" json:"name"`
	TableName   string     `json:"tableName"`
	Properties  []Property `validate:"required" json:"properties,omitempty"`
	PrimaryKeys []string   `validate:"required" json:"primaryKeys,omitempty" gorm:"type:varchar(64)[]"`
	IsDraft     bool       `json:"isDraft"`

	TenantID string `json:"tenantId" validate:"required"`
	Tenant   Tenant `json:"-"`

	CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"`
	UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime"`
}

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.

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 should have a max length of 64
	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" gorm:"-"`
	OptionsStr  *string                 `json:"optionsStr"`
	Comments    string                  `json:"comments"`
	Required    bool                    `json:"required" validate:"required"`
	DataModelID string                  `json:"dataModelId" validate:"required"`
}

Property defines all necessary information of one field

func (*Property) GetOptionsForVarCharField

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

func (*Property) Validate added in v1.1.0

func (p *Property) Validate() error

type Tenant added in v1.2.0

type Tenant struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"`
	UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime"`
}

Tenant is the minimal data isolation layer FIXME: at the very early development, we just have a quite simple tenant model

type VarCharOptions

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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