schema

package
v1.0.0-alpha.33 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Overview

Package schema provides methods to build JSON schema of the collections from user defined models.

Collection model is declared using Go struct tags. The "tigris" tag contains field properties. The following properties are recognised:

  • primary_key - declares primary key of the collection

Composite primary keys defined using optional tag indexes.

Special tag value "-" can be specified to skip field persistence. Unexported fields are not persisted too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(sch *Schema) (driver.Schema, error)

Build converts structured schema to driver schema

func DatabaseModelName

func DatabaseModelName(s interface{}) string

DatabaseModelName returns name of the database derived from the given database model

func FromCollectionModels

func FromCollectionModels(model Model, models ...Model) (map[string]*Schema, error)

FromCollectionModels converts provided model(s) to the schema structure

func FromDatabaseModel

func FromDatabaseModel(dbModel interface{}) (string, map[string]*Schema, error)

FromDatabaseModel converts provided database model to collections schema structures

func ModelName

func ModelName(s interface{}) string

ModelName returns name of the collection derived from the given collection model type. The name is snake case pluralized. If the original name ends with digit then it's not pluralized

Types

type Field

type Field struct {
	Type   string            `json:"type,omitempty"`
	Format string            `json:"format,omitempty"`
	Tags   []string          `json:"tags,omitempty"`
	Desc   string            `json:"description,omitempty"`
	Fields map[string]*Field `json:"properties,omitempty"`
	Items  *Field            `json:"items,omitempty"`

	AutoGenerate bool `json:"autoGenerate,omitempty"`
}

Field represents JSON schema object

type Model

type Model interface{}

Model represents types supported as collection models

type PrimitiveFieldType

type PrimitiveFieldType interface {
	string |
		int | int32 | int64 |
		float32 | float64 |
		[]byte | time.Time | uuid.UUID
}

PrimitiveFieldType represents types supported by non-composite fields

type Schema

type Schema struct {
	Name       string            `json:"title,omitempty"`
	Desc       string            `json:"description,omitempty"`
	Fields     map[string]*Field `json:"properties,omitempty"`
	PrimaryKey []string          `json:"primary_key,omitempty"`
}

Schema is top level JSON schema object

func (*Schema) Build

func (sch *Schema) Build() (driver.Schema, error)

Build converts structured schema to driver schema

Jump to

Keyboard shortcuts

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