dom

package
v0.0.0-...-b226945 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: BSD-2-Clause Imports: 15 Imported by: 6

Documentation

Index

Constants

View Source
const (
	RelA1 Rel = 1 << iota // one a
	RelAN                 // many a
	RelB1                 // one b
	RelBN                 // many b

	RelEmbed   // b embedded in a
	RelRelax   // relaxed integrity checks, b might not yet be declared
	RelInter   // relation has an intermediate model, optionally with extra data
	RelReverse // reversed relation

	Rel11  = RelA1 | RelB1 // one to one
	Rel1N  = RelA1 | RelBN // one to many
	RelN1  = RelAN | RelB1 // many to one
	RelNN  = RelAN | RelBN // many to many
	RelR11 = Rel11 | RelReverse
	RelRN1 = Rel1N | RelReverse
	RelR1N = RelN1 | RelReverse
	RelRNN = RelNN | RelReverse
)
View Source
const ProjectFileName = "project.xelf"

Variables

View Source
var Mod *mod.Src

Mod is the xelf module source for this package that encapsulates the setup required to work with dom specs and gives access to schemas and model beyond their type.

Functions

func DiscoverProject

func DiscoverProject(path string) (string, error)

DiscoverProject looks for a project file based on path and returns a cleaned path.

If path points to a file it check whether the file has a project file name. If path points to a directory, we try to look for a project file in the current and then in all its parents.

func RawSchema

func RawSchema() string

func SetupReg

func SetupReg(reg *lit.Regs)

Types

type Bit

type Bit uint32

Bit is a bit set used for a number of field options.

const (
	BitOpt Bit = 1 << iota
	BitPK
	BitIdx
	BitUniq
	BitAsc
	BitDesc
	BitAuto
	BitRO
)

type Elem

type Elem struct {
	Name  string    `json:"name,omitempty"`
	Type  typ.Type  `json:"type,omitempty"`
	Val   int64     `json:"val,omitempty"`
	Bits  Bit       `json:"bits,omitempty"`
	Extra *lit.Dict `json:"extra,omitempty"`
}

Elem holds additional information for either constants or type parameters.

func (*Elem) Key

func (e *Elem) Key() string

type Env

type Env struct {
	Par exp.Env
}

func FindEnv

func FindEnv(env exp.Env) *Env

func NewEnv

func NewEnv() *Env

func (*Env) Lookup

func (e *Env) Lookup(s *exp.Sym, p cor.Path, eval bool) (lit.Val, error)

func (*Env) Parent

func (e *Env) Parent() exp.Env

type Index

type Index struct {
	Name   string   `json:"name,omitempty"`
	Keys   []string `json:"keys"`
	Unique bool     `json:"unique,omitempty"`
}

Index represents a record model index, mainly used for databases.

type Model

type Model struct {
	Kind   typ.Type  `json:"kind"`
	Name   string    `json:"name"`
	Schema string    `json:"schema,omitempty"`
	Extra  *lit.Dict `json:"extra,omitempty"`
	Elems  []*Elem   `json:"elems,omitempty"`
	Object *Object   `json:"object,omitempty"`
}

Model represents either a bits, enum or obj type and has extra domain information.

func (*Model) Consts

func (m *Model) Consts() []typ.Const

func (*Model) Key

func (m *Model) Key() string

func (*Model) Params

func (m *Model) Params() []typ.Param

func (*Model) Qual

func (m *Model) Qual() string

func (*Model) Qualified

func (m *Model) Qualified() string

func (*Model) Type

func (m *Model) Type() typ.Type

type ModelRef

type ModelRef struct {
	*Model
	Key string
}

ModelRef is a model pointer with an optional field key.

func (ModelRef) String

func (r ModelRef) String() string

type ModelRels

type ModelRels struct {
	*Model
	Out, In, Via []Relation
}

ModelRels contains outgoing, incoming, and intermediate relationships for a model.

func (ModelRels) String

func (r ModelRels) String() string

type Node

type Node interface {
	Qualified() string
}

type NodeEnv

type NodeEnv struct {
	*mod.ModEnv
	ext.Node

	Sub exp.Spec
	// contains filtered or unexported fields
}

func (*NodeEnv) Lookup

func (e *NodeEnv) Lookup(s *exp.Sym, path cor.Path, eval bool) (lit.Val, error)

type Object

type Object struct {
	Indices []*Index `json:"indices,omitempty"`
	OrderBy []string `json:"orderby,omitempty"`
}

Object holds data specific to object types for grouping.

type Project

type Project struct {
	Name    string    `json:"name,omitempty"`
	Extra   *lit.Dict `json:"extra,omitempty"`
	Schemas []*Schema `json:"schemas"`
}

Project is a collection of schemas and project specific extra configuration.

The schema definition can either be declared as part of the project file, or included from an external schema file. Includes should have syntax to filtering the included schema definition.

Extra setting, usually include, but are not limited to, targets and output paths for code generation, paths to look for the project's manifest and history.

func OpenProject

func OpenProject(reg *lit.Regs, path string) (*Project, error)

func ReadProject

func ReadProject(reg *lit.Regs, r io.Reader, path string) (p *Project, _ error)

func (*Project) Model

func (p *Project) Model(key string) *Model

Model returns a model for the qualified key or nil.

func (*Project) Qualified

func (p *Project) Qualified() string

func (*Project) Schema

func (p *Project) Schema(key string) *Schema

Schema returns a schema for key or nil.

type Rel

type Rel uint64

Rel is a bit-set describing the kind of relationship between two models referred to as a and b.

type Relation

type Relation struct {
	Rel
	A, B, Via ModelRef
}

Relation links two models a and b, optionally via a third intermediate model.

func (Relation) String

func (r Relation) String() string

type Relations

type Relations map[string]*ModelRels

Relations maps qualified model names to a collection of all relations for that model.

func Relate

func Relate(pro *Project) (Relations, error)

Relate collects and returns all relations between the models in the given project or an error.

type Schema

type Schema struct {
	Name   string    `json:"name"`
	Extra  *lit.Dict `json:"extra,omitempty"`
	Path   string    `json:"path,omitempty"`
	Use    []string  `json:"use,omitempty"`
	Models []*Model  `json:"models"`
}

Schema is a namespace for models.

var Dom *Schema

func OpenSchema

func OpenSchema(reg *lit.Regs, path string) (s *Schema, _ error)

func ReadSchema

func ReadSchema(reg *lit.Regs, r io.Reader, path string) (s *Schema, _ error)

func (*Schema) Key

func (s *Schema) Key() string

func (*Schema) Model

func (s *Schema) Model(key string) *Model

Model returns a model for key or nil.

func (*Schema) Qualified

func (s *Schema) Qualified() string

Directories

Path Synopsis
Package domtest has default schemas and helpers for testing.
Package domtest has default schemas and helpers for testing.

Jump to

Keyboard shortcuts

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