inference

package
v0.10.11 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package inference defines process that automatically determines the data type of a variable or expression from database meta information

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractColumnConfig

func ExtractColumnConfig(column *sqlparser.Column) (*view.ColumnConfig, error)

func ExtractRelationColumns

func ExtractRelationColumns(join *query.Join) (string, string)

func HasWhitespace

func HasWhitespace(text string) bool

func HintToStruct

func HintToStruct(encoded string, aStructPtr interface{}) error

func IsToOne

func IsToOne(join *query.Join) bool

func ParentAlias

func ParentAlias(join *query.Join) string

ParentAlias returns join parent selector

func PkgPath

func PkgPath(fieldName string, pkgPath string) (fieldPath string)

func SplitByWhitespace

func SplitByWhitespace(fragment string) []string

func SqlxTag

func SqlxTag(tag reflect.StructTag) *io.Tag

func TrimParenthesis

func TrimParenthesis(text string) string

func TryUnmarshalHint

func TryUnmarshalHint(hint string, any interface{}) error

Types

type ColumnParameterNamer

type ColumnParameterNamer func(column *Field) string

type Field

type Field struct {
	view.Field
	Skipped    bool
	Column     *sqlparser.Column
	Pk         *sink.Key
	Tags       Tags
	Ptr        bool
	ColumnCase text.CaseFormat
	Relation   string
}

func NewField

func NewField(rField *reflect.StructField) *Field

func (*Field) EnsureSchema

func (f *Field) EnsureSchema() *state.Schema

func (*Field) StructField

func (f *Field) StructField(opts ...ReflectOption) reflect.StructField

type Imports

type Imports struct {
	Types []string

	Packages []string
	// contains filtered or unexported fields
}

func NewImports

func NewImports() Imports

func (*Imports) AddPackage

func (i *Imports) AddPackage(pkg string)

func (*Imports) AddType

func (i *Imports) AddType(typeName string)

func (*Imports) Clone

func (i *Imports) Clone() *Imports

func (*Imports) DefaultPackageImports

func (i *Imports) DefaultPackageImports() string

func (*Imports) PackageImports

func (i *Imports) PackageImports() string

func (*Imports) RawImports

func (i *Imports) RawImports() string

func (*Imports) TypeImports

func (i *Imports) TypeImports() string

type ModificationSetting

type ModificationSetting struct {
	IsAuxiliary bool
	IndexField  *Field
	PathParam   *Parameter
}

type Parameter

type Parameter struct {
	Explicit bool //explicit parameter are added to the main view as dependency
	state.Parameter
	Repeated State
	Object   State
	ModificationSetting
	SQL         string
	Hint        string
	AssumedType bool
	Connector   string
	InOutput    bool
	Of          string
}

func NewConstParameter

func NewConstParameter(paramName string, paramValue interface{}) *Parameter

func NewPathParameter

func NewPathParameter(name string) *Parameter

func (*Parameter) AppendComposite

func (p *Parameter) AppendComposite(baseParameter *Parameter)

func (*Parameter) DsqlOutputParameterDeclaration added in v0.10.0

func (p *Parameter) DsqlOutputParameterDeclaration() string

func (*Parameter) DsqlParameterDeclaration

func (p *Parameter) DsqlParameterDeclaration() string

func (*Parameter) EnsureCodec

func (p *Parameter) EnsureCodec()

func (*Parameter) EnsureLocation

func (p *Parameter) EnsureLocation()

func (*Parameter) EnsureSchema

func (p *Parameter) EnsureSchema()

func (*Parameter) FieldDeclaration

func (p *Parameter) FieldDeclaration(embedRoot string, embed map[string]string, def *view.TypeDefinition) string

func (*Parameter) HasDataType

func (p *Parameter) HasDataType() bool

func (*Parameter) HasSchema

func (p *Parameter) HasSchema() bool

func (*Parameter) IndexFieldDeclaration added in v0.10.0

func (p *Parameter) IndexFieldDeclaration() string

func (*Parameter) IndexVariable

func (p *Parameter) IndexVariable() string

func (*Parameter) LocalVariable

func (p *Parameter) LocalVariable() string

func (*Parameter) MergeFrom

func (p *Parameter) MergeFrom(info *Parameter)

func (*Parameter) SyncObject

func (p *Parameter) SyncObject()

type ReflectOption

type ReflectOption func(r *reflectOptions)

func WithStructTag

func WithStructTag() ReflectOption

type Relation

type Relation struct {
	Name        string
	Join        *query.Join
	ParentField *Field
	KeyField    *Field
	Cardinality state.Cardinality
	*Spec
}

Relation defines relation

type Selector

type Selector []string

Selector defines selector

func (Selector) Absolute

func (s Selector) Absolute(loc ...string) string

func (Selector) Leaf

func (s Selector) Leaf() Selector

func (Selector) Name

func (s Selector) Name() string

func (Selector) Path

func (s Selector) Path(loc ...string) string

func (Selector) Resolve

func (s Selector) Resolve(prefix string, loc ...string) string

type Spec

type Spec struct {
	Namespace   string
	Parent      *Spec
	Package     string
	IsAuxiliary bool
	Table       string
	SQL         string
	SQLArgs     []interface{}
	Columns     sqlparser.Columns

	Fk        map[string]sink.Key
	Type      *Type
	Relations []*Relation
	// contains filtered or unexported fields
}

Spec defines table/sql base specification

func NewSpec

func NewSpec(ctx context.Context, db *sql.DB, messages *msg.Messages, table, SQL string, SQLArgs ...interface{}) (*Spec, error)

NewSpec discover column derived type for supplied SQL/table

func (*Spec) AddRelation

func (s *Spec) AddRelation(name string, join *query.Join, spec *Spec, cardinality state.Cardinality) error

AddRelation adds relations

func (*Spec) BuildType

func (s *Spec) BuildType(pkg, name string, cardinality state.Cardinality, whitelist, blacklist map[string]bool) error

BuildType build a type from infered table/SQL definition

func (*Spec) EnsureRelationType

func (s *Spec) EnsureRelationType()

func (*Spec) Fields

func (s *Spec) Fields(includeHas bool, doc state.Documentation) []*view.Field

func (*Spec) NormalizeSQL added in v0.10.1

func (s *Spec) NormalizeSQL()

func (*Spec) PkStructQL

func (s *Spec) PkStructQL(selector Selector) (*Field, string)

PkStructQL crates a PK struct SQL

func (*Spec) Selector

func (s *Spec) Selector(rootPath string) Selector

Selector returns current sepcifiction selector (path from root)

func (*Spec) TypeDefinition

func (s *Spec) TypeDefinition(wrapper string, includeHas bool, doc state.Documentation) *view.TypeDefinition

TypeDefinition builds spec based tyep definition

func (*Spec) ViewSQL

func (s *Spec) ViewSQL(columnParameter ColumnParameterNamer) string

ViewSQL return structQL SQL for relation

type State

type State []*Parameter

State defines datly view/resource parameters

func NewState

func NewState(modulePath, dataType string, types *xreflect.Types) (State, error)

NewState creates a state from state go struct

func (State) AddDescriptions

func (s State) AddDescriptions(doc state.Documentation)

func (*State) AdjustOutput

func (s *State) AdjustOutput() error

func (*State) Append

func (s *State) Append(params ...*Parameter) bool

Append append parameter

func (*State) AppendConst

func (s *State) AppendConst(constants map[string]interface{})

func (*State) AppendParameters

func (s *State) AppendParameters(parameters ...state.Parameters)

func (*State) AppendViewParameters

func (s *State) AppendViewParameters(params ...*state.Parameter)

func (State) BodyField

func (s State) BodyField() string

func (*State) BodyParameter added in v0.10.0

func (s *State) BodyParameter() *Parameter

func (State) Clone

func (s State) Clone() State

func (State) Compact

func (s State) Compact(modulePath string, registry *xreflect.Types) (State, error)

func (State) DsqlOutputParameterDeclaration added in v0.10.0

func (s State) DsqlOutputParameterDeclaration() string

DsqlOutputParameterDeclaration returns dql parameter declaration

func (State) DsqlParameterDeclaration

func (s State) DsqlParameterDeclaration() string

DsqlParameterDeclaration returns dql parameter declaration

func (State) EnsureReflectTypes

func (s State) EnsureReflectTypes(modulePath string, pkg string, registry *xreflect.Types) error

func (State) EnsureStructQLTypes added in v0.9.7

func (s State) EnsureStructQLTypes() error

func (State) Expand

func (s State) Expand(text string) string

func (State) Explicit

func (s State) Explicit() State

Implicit filters implicit parameters

func (State) FilterByKind

func (s State) FilterByKind(kind state.Kind) State

FilterByKind filters state parameter by kind

func (*State) GetOutputParameter

func (s *State) GetOutputParameter() *Parameter

func (State) HandlerLocalVariables

func (s State) HandlerLocalVariables() ([]string, string)

HandlerLocalVariables returns golang handler local variables reassigned from state

func (State) Has

func (s State) Has(name string) bool

Has returns true if state already has a parameter

func (State) Implicit

func (s State) Implicit() State

Implicit filters implicit parameters

func (State) IndexByName

func (s State) IndexByName() map[string]*Parameter

IndexByName indexes parameter by name

func (State) IndexByPathIndex

func (s State) IndexByPathIndex() map[string]*Parameter

IndexByPathIndex indexes parameter by index variable

func (State) Lookup

func (s State) Lookup(name string) *Parameter

Lookup returns matched paramter

func (State) MetaViewSQL

func (s State) MetaViewSQL() *Parameter

func (State) NormalizeComposites

func (s State) NormalizeComposites() (State, error)

NormalizeComposites normalizes state

func (State) Parameters

func (s State) Parameters() state.Parameters

func (State) ReflectType

func (s State) ReflectType(pkgPath string, lookupType xreflect.LookupType) (reflect.Type, error)

func (State) RemoveReserved

func (s State) RemoveReserved() State

func (*State) StateForSQL

func (s *State) StateForSQL(SQL string, isRoot bool) State

type Table

type Table struct {
	Name         string
	Namespace    string
	Columns      sqlparser.Columns
	QueryColumns sqlparser.Columns

	Tables         []*Table
	OutputJSONHint string
	// contains filtered or unexported fields
}

func NewTable

func NewTable(ctx context.Context, db *sql.DB, SQL string) (*Table, error)

func (*Table) AppendTable

func (t *Table) AppendTable(table *Table)

func (*Table) Detect

func (t *Table) Detect(ctx context.Context, db *sql.DB) (err error)

func (*Table) HasNamespace

func (t *Table) HasNamespace(ns string) bool

func (*Table) HasTable

func (t *Table) HasTable(table string) bool

func (*Table) Lookup

func (t *Table) Lookup(column string) *sqlparser.Column

type TagValue

type TagValue []string

func (*TagValue) Append

func (e *TagValue) Append(element string)

Append appends tag value element

type Tags

type Tags struct {
	// contains filtered or unexported fields
}

func (*Tags) Init

func (t *Tags) Init(tag string)

func (*Tags) Set

func (t *Tags) Set(tag string, value TagValue)

Set sets tag value

func (*Tags) Stringify

func (t *Tags) Stringify() string

Stringify return text representation of struct tag

func (*Tags) ViewTag added in v0.10.3

func (t *Tags) ViewTag(table string)

type Type

type Type struct {
	Package     string
	Name        string
	Cardinality state.Cardinality
	PkFields    []*Field

	RelationFields []*Field
	// contains filtered or unexported fields
}

func NewType

func NewType(packageName string, name string, rType reflect.Type) (*Type, error)

func (*Type) AddRelation

func (t *Type) AddRelation(name string, spec *Spec, relation *Relation) *Field

func (*Type) AppendColumnField

func (t *Type) AppendColumnField(column *sqlparser.Column, skipped bool, table string) (*Field, error)

func (*Type) ByColumn

func (t *Type) ByColumn(name string) *Field

func (*Type) ColumnFields

func (t *Type) ColumnFields(table string, doc state.Documentation) []*view.Field

func (*Type) ExpandType

func (t *Type) ExpandType(simpleName string) string

func (*Type) Fields

func (t *Type) Fields(opts ...ReflectOption) []reflect.StructField

func (*Type) SimplePackage added in v0.9.0

func (t *Type) SimplePackage() string

func (*Type) TypeName

func (t *Type) TypeName() string

Jump to

Keyboard shortcuts

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