Documentation ¶
Index ¶
- Constants
- func DetectCase(data ...string) string
- func ParseType(dataType string) (reflect.Type, error)
- func TemplateField(name string, rType reflect.Type) (reflect.StructField, error)
- type Accessor
- type Accessors
- type Batch
- type Cardinality
- type CaseFormat
- type Codec
- type CodecFn
- type Collector
- func (r *Collector) Dest() interface{}
- func (r *Collector) Fetched()
- func (r *Collector) Lock() *sync.Mutex
- func (r *Collector) MergeData()
- func (r *Collector) NewItem() func() interface{}
- func (r *Collector) ParentPlaceholders() ([]interface{}, string)
- func (r *Collector) Relation() *Relation
- func (r *Collector) Relations(selector *Selector) []*Collector
- func (r *Collector) Resolve(column io.Column) func(ptr unsafe.Pointer) interface{}
- func (r *Collector) Slice() (unsafe.Pointer, *xunsafe.Slice)
- func (r *Collector) SupportsParallel() bool
- func (r *Collector) View() *View
- func (r *Collector) Visitor() Visitor
- func (r *Collector) WaitIfNeeded()
- type Column
- type ColumnIndex
- type Columns
- type CommonParams
- type Config
- type Connector
- type ConnectorSlice
- type Connectors
- type Constraints
- type CriteriaSanitizer
- type Definition
- type Evaluator
- type Field
- type Kind
- type Location
- type MatchStrategy
- type Method
- type Metrics
- type Names
- type Option
- type Param
- type ParamName
- type ParamState
- type Parameter
- func (p *Parameter) ConvertAndSet(ctx context.Context, paramPtr unsafe.Pointer, value string, selector *Selector) error
- func (p *Parameter) Init(ctx context.Context, view *View, resource *Resource, structType reflect.Type) error
- func (p *Parameter) IsRequired() bool
- func (p *Parameter) Set(ptr unsafe.Pointer, value interface{}) error
- func (p *Parameter) SetAccessor(accessor *Accessor)
- func (p *Parameter) SetPresenceField(structType reflect.Type) error
- func (p *Parameter) UpdatePresence(presencePtr unsafe.Pointer)
- func (p *Parameter) Validate() error
- func (p *Parameter) Value(values interface{}) (interface{}, error)
- func (p *Parameter) View() *View
- type ParametersIndex
- type ParametersSlice
- type ReferenceView
- type Relation
- type RelationsSlice
- type Resource
- func (r *Resource) AddConnectors(connectors ...*Connector)
- func (r *Resource) AddLoggers(loggers ...*logger.Adapter)
- func (r *Resource) AddParameters(parameters ...*Parameter)
- func (r *Resource) AddViews(views ...*View)
- func (r *Resource) ConnectorByName() map[string]*Connector
- func (r *Resource) FindConnector(view *View) (*Connector, error)
- func (r *Resource) GetConnectors() Connectors
- func (r *Resource) GetTypes() Types
- func (r *Resource) GetViews() Views
- func (r *Resource) Init(ctx context.Context, options ...interface{}) error
- func (r *Resource) LoadObject(ctx context.Context, URL string) (storage.Object, error)
- func (r *Resource) LoadText(ctx context.Context, URL string) (string, error)
- func (r *Resource) MergeFrom(resource *Resource, types Types)
- func (r *Resource) SetTypes(types Types)
- func (r *Resource) TypeName(p reflect.Type) (string, bool)
- func (r *Resource) View(name string) (*View, error)
- type Sanitizer
- type Schema
- type Selector
- type Selectors
- type Template
- type Types
- type VeltyCodec
- type View
- func (v *View) CanUseSelectorCriteria() bool
- func (v *View) CanUseSelectorLimit() bool
- func (v *View) CanUseSelectorOffset() bool
- func (v *View) CanUseSelectorOrderBy() bool
- func (v *View) Collector(dest interface{}, supportParallel bool) *Collector
- func (v *View) ColumnByName(name string) (*Column, bool)
- func (v *View) DataType() reflect.Type
- func (v *View) Db() (*sql.DB, error)
- func (v *View) IndexedColumns() ColumnIndex
- func (v *View) Init(ctx context.Context, resource *Resource) error
- func (v *View) IsHolder(value string) bool
- func (v *View) LimitWithSelector(selector *Selector) int
- func (v *View) ShouldTryDiscover() bool
- func (v *View) Source() string
- func (v *View) UseParamBindingPositions() bool
- type ViewSlice
- type Views
- type Visitor
Constants ¶
const ( SafeColumn = "Safe_Column" SafeValue = "Safe_Value" SafeInt = "Safe_Int" SafeString = "Safe_String" SafeBool = "Safe_Bool" SafeFloat = "Safe_Float" Criteria = "criteria" )
const (
VeltyCriteriaCodec = "VeltyCriteria"
)
Variables ¶
This section is empty.
Functions ¶
func DetectCase ¶ added in v0.2.1
DetectCase detect case format
func TemplateField ¶
Types ¶
type Cardinality ¶
type Cardinality string
const ( One Cardinality = "One" Many Cardinality = "Many" )
type CaseFormat ¶
type CaseFormat string
const ( UpperUnderscoreShort CaseFormat = "uu" UpperUnderscore CaseFormat = "upperunderscore" LowerUnderscoreShort CaseFormat = "lu" LowerUnderscore CaseFormat = "lowerunderscore" UpperCamelShort CaseFormat = "uc" UpperCamel CaseFormat = "uppercamel" LowerCamelShort CaseFormat = "lc" LowerCamel CaseFormat = "lowercamel" LowerShort CaseFormat = "l" Lower CaseFormat = "lower" UpperShort CaseFormat = "u" Upper CaseFormat = "upper" )
func (*CaseFormat) Init ¶
func (f *CaseFormat) Init() error
type Codec ¶
type Codec struct { Name string Source string SourceURL string Schema *Schema // contains filtered or unexported fields }
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector collects and build result from view fetched from Database If View or any of the View.With MatchStrategy support Parallel fetching, it is important to call MergeData when all needed view was fetched
func NewCollector ¶
func NewCollector(slice *xunsafe.Slice, view *View, dest interface{}, supportParallel bool) *Collector
NewCollector creates a collector
func (*Collector) MergeData ¶
func (r *Collector) MergeData()
MergeData merges view with Collectors produced via Relations It is sufficient to call it on the most Parent Collector to produce result
func (*Collector) NewItem ¶
func (r *Collector) NewItem() func() interface{}
NewItem creates and return item provider Each produced item is automatically appended to the dest
func (*Collector) ParentPlaceholders ¶
ParentPlaceholders if Collector doesn't support parallel fetching and has a Parent, it will return a parent _field values and column name that the relation was created from, otherwise empty slice and empty string i.e. if Parent Collector collects Employee{AccountId: int}, Column.Name is account_id and Collector collects Account it will extract and return all the AccountId that were accumulated and account_id
func (*Collector) Relations ¶
Relations creates and register new Collector for each Relation present in the Selector.Columns if View allows use Selector.Columns
func (*Collector) SupportsParallel ¶
SupportsParallel if Collector supports parallelism, it means that his Relations can fetch view in the same time Later on it will be merged with the parent Collector
func (*Collector) WaitIfNeeded ¶
func (r *Collector) WaitIfNeeded()
type Column ¶
type Column struct { Name string `json:",omitempty"` DataType string `json:",omitempty"` Expression string `json:",omitempty"` Filterable bool `json:",omitempty"` Nullable bool `json:",omitempty"` Default string `json:",omitempty"` Format string `json:",omitempty"` // contains filtered or unexported fields }
Column represents view View column
func (*Column) ColumnType ¶ added in v0.2.1
func (*Column) SqlExpression ¶
SqlExpression builds column sql expression if any expression specified in format: Expression AS Name
type ColumnIndex ¶ added in v0.2.1
ColumnIndex represents *Column registry.
func (ColumnIndex) Lookup ¶ added in v0.2.1
func (c ColumnIndex) Lookup(name string) (*Column, error)
Lookup returns Column with given name.
func (ColumnIndex) Register ¶ added in v0.2.1
func (c ColumnIndex) Register(caser format.Case, column *Column)
Register registers *Column
func (ColumnIndex) RegisterHolder ¶ added in v0.2.1
func (c ColumnIndex) RegisterHolder(relation *Relation) error
RegisterHolder looks for the Column by Relation.Column name. If it finds registers that Column with Relation.Holder key.
func (ColumnIndex) RegisterWithName ¶ added in v0.2.1
func (c ColumnIndex) RegisterWithName(name string, column *Column)
type Columns ¶
type Columns []*Column
Columns wrap slice of Column
type CommonParams ¶
type Config ¶
type Config struct { //TODO: Should order by be a slice? OrderBy string `json:",omitempty"` Limit int `json:",omitempty"` Constraints *Constraints LimitParam *Parameter OffsetParam *Parameter FieldsParam *Parameter OrderByParam *Parameter CriteriaParam *Parameter }
Config represent a view config selector
type Connector ¶
type Connector struct { shared.Reference Secret *scy.Resource `json:",omitempty"` Name string Driver string DSN string // contains filtered or unexported fields }
Connector represents database/sql named connection config
func (*Connector) Db ¶
Db creates connection to the DB. It is important to not close the DB since the connection is shared.
type ConnectorSlice ¶
type ConnectorSlice []*Connector
ConnectorSlice represents Slice of *Connector
func (ConnectorSlice) Index ¶
func (c ConnectorSlice) Index() Connectors
Index indexes Connectors by Connector.Name.
func (ConnectorSlice) Init ¶
func (c ConnectorSlice) Init(ctx context.Context, connectors Connectors) error
Init initializes each connector
type Connectors ¶
Connectors represents Connector registry Key was produced based on Connector.Name
func (Connectors) Lookup ¶
func (v Connectors) Lookup(name string) (*Connector, error)
Lookup returns Connector by Connector.Name
func (*Connectors) Register ¶
func (v *Connectors) Register(connector *Connector)
Register registers connector
type Constraints ¶
type Constraints struct { Criteria bool OrderBy bool Limit bool Offset bool Filterable []string SqlMethods []*Method // contains filtered or unexported fields }
Constraints configure what can be selected by Selector For each _field, default value is `false`
func (*Constraints) SqlMethodsIndexed ¶ added in v0.2.1
func (c *Constraints) SqlMethodsIndexed() map[string]*Method
type CriteriaSanitizer ¶ added in v0.2.1
type CriteriaSanitizer struct { Columns ColumnIndex Placeholders []interface{} }
func NewCriteria ¶ added in v0.2.1
func NewCriteria(columns ColumnIndex) *CriteriaSanitizer
func (*CriteriaSanitizer) AsBinding ¶ added in v0.2.1
func (c *CriteriaSanitizer) AsBinding(value interface{}) string
type Definition ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
func NewEvaluator ¶ added in v0.2.1
type Field ¶
type Kind ¶
type Kind string
Kind represents parameter location Parameter value can be retrieved from the i.e. HTTP Header, Path Variable or using other View
type MatchStrategy ¶
type MatchStrategy string
MatchStrategy in some cases it might be better to fetch parent View view and all Relation view in the same time and merge it on the backend side in those cases ReadAll strategy will do that. in other cases it might be better to filter Relation view and fetch only those records that matches with View view in those cases ReadMatched will do that.
const ( ReadAll MatchStrategy = "read_all" // read all and later we match on backend side ReadMatched MatchStrategy = "read_matched" // read parent view and then filter id to match with the current view ReadDerived MatchStrategy = "read_derived" // use parent sql selector to add criteria to the relation view, this can only work if the connector of the relation view and parent view is the same )
func (MatchStrategy) SupportsParallel ¶
func (s MatchStrategy) SupportsParallel() bool
SupportsParallel indicates whether MatchStrategy support parallel read.
func (MatchStrategy) Validate ¶
func (s MatchStrategy) Validate() error
Validate checks if MatchStrategy is valid
type ParamName ¶
type ParamName string
ParamName represents name of parameter in given Location.Kind i.e. if you want to extract lang from query string: ?foo=bar&lang=eng required Kind is QueryKind and ParamName `lang`
type ParamState ¶
type ParamState struct { Values interface{} `json:",omitempty"` Has interface{} `json:",omitempty"` }
Selector allows customizing view fetched from Database
func (*ParamState) Init ¶
func (s *ParamState) Init(view *View)
type Parameter ¶
type Parameter struct { shared.Reference Name string PresenceName string In *Location Required *bool Description string Style string Schema *Schema Codec *Codec Positions []int `json:",omitempty"` // contains filtered or unexported fields }
Parameter describes parameters used by the Criteria to filter the view.
func (*Parameter) ConvertAndSet ¶
func (*Parameter) Init ¶
func (p *Parameter) Init(ctx context.Context, view *View, resource *Resource, structType reflect.Type) error
Init initializes Parameter
func (*Parameter) IsRequired ¶
func (*Parameter) SetAccessor ¶
func (*Parameter) SetPresenceField ¶
func (*Parameter) UpdatePresence ¶
type ParametersIndex ¶
ParametersIndex represents Parameter map indexed by Parameter.Name
func (ParametersIndex) Lookup ¶
func (p ParametersIndex) Lookup(paramName string) (*Parameter, error)
Lookup returns Parameter with given name
func (ParametersIndex) Register ¶
func (p ParametersIndex) Register(parameter *Parameter)
Register registers parameter
type ParametersSlice ¶
type ParametersSlice []*Parameter
ParametersSlice represents slice of parameters
func (ParametersSlice) Filter ¶
func (p ParametersSlice) Filter(kind Kind) ParametersIndex
Filter filters ParametersSlice with given Kind and creates Template
func (ParametersSlice) Index ¶
func (p ParametersSlice) Index() ParametersIndex
Index indexes parameters by Parameter.Name
type ReferenceView ¶
type ReferenceView struct { View // event type Column string // Field string // // contains filtered or unexported fields }
ReferenceView represents referenced View In our example it would be Account
func (*ReferenceView) Init ¶
func (r *ReferenceView) Init(_ context.Context, _ *Resource) error
Init initializes ReferenceView
func (*ReferenceView) Validate ¶
func (r *ReferenceView) Validate() error
Validate checks if ReferenceView is valid
type Relation ¶
type Relation struct { Name string `json:",omitempty"` Of *ReferenceView `json:",omitempty"` Cardinality Cardinality `json:",omitempty"` //One, or Many Column string `json:",omitempty"` //Represents parent column that would be used to assemble nested objects. In our example it would be Employee#AccountId ColumnAlias string `json:",omitempty"` //Represents column alias, can be specified if $shared.Criteria / $shared.ColumnInPosition is inside the "from" statement Holder string `json:",omitempty"` //Represents column created due to the merging. In our example it would be Employee#Account IncludeColumn bool `json:",omitempty"` //tells if Column _field should be kept in the struct type. In our example, if set false in produced Employee would be also AccountId _field // contains filtered or unexported fields }
Relation used to build more complex View that represents database tables with relations one-to-one or many-to-many In order to understand it better our example is: Parent View represents Employee{AccountId: int}, Relation represents Account{Id: int} We want to create result like: Employee{Account{Id:int}}
type RelationsSlice ¶
type RelationsSlice []*Relation
RelationsSlice represents slice of Relation
func (RelationsSlice) Columns ¶
func (r RelationsSlice) Columns() []string
Columns extract Relation.Column from RelationsSlice
func (RelationsSlice) Index ¶
func (r RelationsSlice) Index() map[string]*Relation
Index indexes Relations by Relation.Holder
func (RelationsSlice) PopulateWithResolve ¶
func (r RelationsSlice) PopulateWithResolve() []*Relation
PopulateWithResolve filters RelationsSlice by the columns that won't be present in Database due to the removing StructField after assembling nested StructType.
func (RelationsSlice) PopulateWithVisitor ¶
func (r RelationsSlice) PopulateWithVisitor() []*Relation
PopulateWithVisitor filters RelationsSlice by the columns that will be present in Database, and because of that they wouldn't be resolved as unmapped columns.
type Resource ¶
type Resource struct { Metrics *Metrics SourceURL string `json:",omitempty"` Connectors []*Connector Views []*View `json:",omitempty"` Parameters []*Parameter `json:",omitempty"` Types []*Definition Loggers logger.Adapters `json:",omitempty"` ModTime time.Time `json:",omitempty"` // contains filtered or unexported fields }
Resource represents grouped view needed to build the View can be loaded from i.e. yaml file
func EmptyResource ¶
func EmptyResource() *Resource
func LoadResourceFromURL ¶
LoadResourceFromURL load resource from URL
func NewResource ¶
NewResource creates a Resource and register provided Types
func NewResourceFromURL ¶
func NewResourceFromURL(ctx context.Context, url string, types Types, visitors codec.Visitors) (*Resource, error)
NewResourceFromURL loads and initializes Resource from file .yaml
func (*Resource) AddConnectors ¶
AddConnectors register connectors in the resource
func (*Resource) AddLoggers ¶
AddLoggers register loggers in the resource
func (*Resource) AddParameters ¶
AddParameters register parameters in the resource
func (*Resource) ConnectorByName ¶
func (*Resource) GetConnectors ¶
func (r *Resource) GetConnectors() Connectors
GetConnectors returns Connectors supplied with the Resource
func (*Resource) LoadObject ¶ added in v0.2.1
type Sanitizer ¶ added in v0.2.1
type Sanitizer struct {
// contains filtered or unexported fields
}
type Schema ¶
type Schema struct { Name string `json:",omitempty"` DataType string `json:",omitempty"` // contains filtered or unexported fields }
Schema represents View as Go type.
func (*Schema) AutoGen ¶
AutoGen indicates whether Schema was generated using ColumnTypes fetched from DB or was passed programmatically.
func (*Schema) Init ¶
func (c *Schema) Init(columns []*Column, relations []*Relation, viewCaseFormat format.Case, types Types) error
Init build struct type
type Selector ¶
type Selector struct { DatabaseFormat format.Case OutputFormat format.Case Columns []string `json:",omitempty"` Fields []string `json:",omitempty"` OrderBy string `json:",omitempty"` Offset int `json:",omitempty"` Limit int `json:",omitempty"` Parameters ParamState `json:",omitempty"` Criteria string `json:",omitempty"` Placeholders []interface{} `json:",omitempty"` // contains filtered or unexported fields }
Selector allows customizing view fetched from Database
func NewSelector ¶ added in v0.2.1
func NewSelector() *Selector
type Template ¶
type Template struct { Source string `json:",omitempty"` SourceURL string `json:",omitempty"` Schema *Schema `json:",omitempty"` PresenceSchema *Schema `json:",omitempty"` Parameters []*Parameter `json:",omitempty"` // contains filtered or unexported fields }
func (*Template) EvaluateSource ¶
func (*Template) IsActualTemplate ¶ added in v0.2.1
type VeltyCodec ¶ added in v0.2.1
type VeltyCodec struct {
// contains filtered or unexported fields
}
func NewVeltyCodec ¶ added in v0.2.1
type View ¶
type View struct { shared.Reference Connector *Connector Standalone bool `json:",omitempty"` Name string Alias string `json:",omitempty"` Table string `json:",omitempty"` From string `json:",omitempty"` FromURL string Exclude []string `json:",omitempty"` Columns []*Column `json:",omitempty"` InheritSchemaColumns bool `json:",omitempty"` CaseFormat CaseFormat `json:",omitempty"` Criteria string `json:",omitempty"` Selector *Config `json:",omitempty"` Template *Template `json:",omitempty"` Schema *Schema `json:",omitempty"` With []*Relation `json:",omitempty"` MatchStrategy MatchStrategy `json:",omitempty"` Batch *Batch `json:",omitempty"` Logger *logger.Adapter `json:"-"` Counter logger.Counter `json:"-"` Caser format.Case `json:",omitempty"` DiscoverCriteria *bool AllowNulls *bool UseBindingPositions *bool // contains filtered or unexported fields }
View represents a view View
func ViewReference ¶
ViewReference creates a view reference
func (*View) CanUseSelectorCriteria ¶
CanUseSelectorCriteria indicates if Selector.Criteria can be used
func (*View) CanUseSelectorLimit ¶
CanUseSelectorLimit indicates if Selector.Limit can be used
func (*View) CanUseSelectorOffset ¶
CanUseSelectorOffset indicates if Selector.Offset can be used
func (*View) CanUseSelectorOrderBy ¶
CanUseSelectorOrderBy indicates if Selector.OrderBy can be used
func (*View) ColumnByName ¶
ColumnByName returns Column by Column.Name
func (*View) IndexedColumns ¶
func (v *View) IndexedColumns() ColumnIndex
IndexedColumns returns Columns
func (*View) Init ¶
Init initializes View using view provided in Resource. i.e. If View, Connector etc. should inherit from others - it has te bo included in Resource. It is important to call Init for every View because it also initializes due to the optimization reasons.
func (*View) LimitWithSelector ¶
LimitWithSelector returns Selector.Limit if it is allowed by the View to use Selector.Columns (see Constraints.Limit)
func (*View) ShouldTryDiscover ¶ added in v0.2.1
func (*View) Source ¶
Source returns database view source. It prioritizes From, Table then View.Name
func (*View) UseParamBindingPositions ¶ added in v0.2.1
Source Files ¶
- accessors.go
- collector.go
- column.go
- columns.go
- config.go
- connector.go
- connectors.go
- definition.go
- format.go
- key.go
- location.go
- match.go
- metric.go
- names.go
- option.go
- parameter.go
- parameters.go
- relation.go
- relations.go
- resource.go
- schema.go
- selector.go
- selectors.go
- sql.go
- template.go
- types.go
- velty.go
- view.go
- views.go