Documentation
¶
Index ¶
- Constants
- 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 ColumnSlice
- type Columns
- type CommonParams
- type Config
- type Connector
- type ConnectorSlice
- type Connectors
- type Constraints
- type Definition
- type Evaluator
- type Field
- type Kind
- type Location
- type MatchStrategy
- 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) error
- func (p *Parameter) Init(ctx context.Context, 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, types Types, visitors visitor.Visitors) 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) View(name string) (*View, error)
- type Schema
- type Selector
- type Selectors
- type Template
- func (t *Template) AccessorByName(name string) (*Accessor, error)
- func (t *Template) EvaluateCriteria(externalParams, presenceMap interface{}, parent *View) (string, error)
- func (t *Template) EvaluateSource(externalParams, presenceMap interface{}, parent *View) (string, error)
- func (t *Template) Init(ctx context.Context, resource *Resource, view *View) error
- type Types
- type View
- func (v *View) CanUseSelectorColumns() bool
- 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() Columns
- 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) SelectedColumns(selector *Selector) ([]*Column, error)
- func (v *View) Source() string
- type ViewSlice
- type Views
- type Visitor
Constants ¶
const ( Pagination = "$PAGINATION" Criteria = "$CRITERIA" WhereCriteria = "$WHERE_CRITERIA" ColumnsIn = "$COLUMN_IN" WherePrefix = "WHERE_" AndPrefix = "AND_" OrPrefix = "OR_" )
Variables ¶
This section is empty.
Functions ¶
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 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) SqlExpression ¶
SqlExpression builds column sql expression if any expression specified in format: Expression AS Name
type ColumnSlice ¶
type ColumnSlice []*Column
ColumnSlice wrap slice of Column
type Columns ¶
Columns represents *Column registry.
func (Columns) RegisterHolder ¶
RegisterHolder looks for the Column by Relation.Column name. If it finds registers that Column with Relation.Holder key.
func (Columns) RegisterWithName ¶
type CommonParams ¶
type Config ¶
type Config struct {
//TODO: Should order by be a slice?
OrderBy string `json:",omitempty"`
Limit int `json:",omitempty"`
Constraints *Constraints
}
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 ¶
Constraints configure what can be selected by Selector For each field, default value is `false`
type Definition ¶
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
// contains filtered or unexported fields
}
Parameter describes parameters used by the Criteria to filter the view.
func (*Parameter) ConvertAndSet ¶
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 // EventType.id
// 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
Connectors []*Connector
Views []*View
Parameters []*Parameter
Types []*Definition
Loggers logger.Adapters
// 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 visitor.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
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 {
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"`
// contains filtered or unexported fields
}
Selector allows customizing view fetched from Database
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) EvaluateCriteria ¶
func (*Template) EvaluateSource ¶
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"`
// contains filtered or unexported fields
}
View represents a view View
func ViewReference ¶
ViewReference creates a view reference
func (*View) CanUseSelectorColumns ¶
CanUseSelectorColumns indicates if Selector.Columns can be used
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 ¶
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) SelectedColumns ¶
SelectedColumns returns columns selected by Selector if it is allowed by the View to use Selector.Columns (see Constraints.Columns) or View.Columns