view

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 65 Imported by: 1

README

Introduction

Resource:

View:

  • Reader
  • Executor

Parameters:

  • External
  • Internal

Resource

Resource groups and represents set of Views, Connectors, Parameters and Types needed to build all views provided in resorce. In resource following sections can be defined:

Section Description Type Required
SourceURL string false
Metrics View specific Metrics configuration inheritable by other Views Metrics Metrics false
Connectors Database connector definitions inheritable by other Views Connectors []Connector false
Views Views definitions provided by the resource []View false
Parameters Parameters configurations inheritable by other Views Parameters []Parameter false
Types Inlined types definitions []Type false
Loggers Loggers inheritable by other Views Loggers []Logger false

View

For View description read one of the following docs: programmatically usage or yaml usage

Section Description Type Required Default
Ref Other View name that given View should inherit from string false
Connector Connector used by the View Connector true
Name Unique view name string, unique across the Resource true
Alias View table alias string false
Table Table name. string Table, FromURL or From need to be specified
From SQL inner select statement that will be used as source of data string Table, FromURL or From need to be specified
FromURL Source of the SQL in case when SQL is specified in different file string Table, FromURL or From need to be specified
Exclude Columns that should not be exposed when column detection is performed []string false
Columns Explicitly specified columns that current View can use []Column true
InheritSchemaColumns Indicates whether all Columns that not match Struct Type should be removed or not bool false false
CaseFormat Database columns case format CaseFormat false lowerunderscore
Criteria Dynamic criteria expanded with the parameters values string false
Selector Selector configuration SelectorConfig false
Template Template configuration using parameters and velty syntax Template false
Schema View schema type Schema false
With View relations in order to produce results with nested objects []Relation false
MatchStrategy Match strategy specific for given View MatchStrategy false read_matched
Batch Batch configuration specific for given View Batch false Batch{Parent: 10000}
Logger Logger specific for given View Logger false
Counter Metrics specific for given View Metrics false

Column

Section Description Type Required Default
Name Database column name string true
DataType Column type enum: Int, Float, Float64, Bool, String, Date, Time false
Expression SQL expression i.e. COALESCE(price, 0) string false
Filterable Indicates whether column can be used using Selector criteria or not bool false false
Nullable Indicates whether column is nullable or not. In case if table is specified and DataType is not Time nor Date, Datly will automaticaly add COALESCE for the expression bool false false
Default Default output value that will be replaced when zero value occur string false
Format Date output format string false

SelectorConfig

SelectorConfig holds information about what can be used on specific View using Selectors built from the Request data.

Section Description Type Required Default
OrderBy Default Column that will be used to Sorted string false
Limit Maximum and default limit that can be used on the View int false No default and maximum limit
Constraints Selector constraints Constraints false everything disabled

Constraints

By default everything is forbidden. In order to allow datly create and populate Selectors from Http requests, it need to be explicitly enabled.

Section Description Type Required Default
Criteria Allows to parse _criteria into SQL statement boolean false false
OrderBy Allows to parse _orderBy into SQL order by boolean false false
Limit Allows to parse _limit into SQL limit boolean false false
Offset Allows to parse _orrset into SQL offset boolean false false
Filterable Allowed columns to be used in the criteria, * in case of allowed all columns []string false

Parameter

Parameters are defined in order to read data specific for the given http request.

Section Description Type Required Default
Ref Other Parameter name that given Parameter will inherit from string false
Name Identifier used to access parameter value in the templates string true
PresenceName Identifier used to check if parameter was set in the templates string false same as Name
In Source of the parameter Location true
Required Indicates if parameter is required or not boolean false false
Description Parameter description string false
Schema Schema configuration Schema true
Codec Codec configuration Codec false

Location

Section Description Type Required
Kind Represents the source of the parameter i.e. Header, QueryParam. enum: query,header, cookie, data_view, body, env true
Name Parameter source identifier i.e. Authorization, userId string true

Codec

In some cases it is needed to transform raw parameter value to some different value. For example Authorization Header with JWT Token. In this case it is needed to provide and configure Codec that will transform raw JWT token into some struct. The Codec need to be created programmatically and provided during the Resource initialization.

The interface needed to be implemented by the Codec:

Value(ctx context.Context, raw string) (interface{}, error)
Section Description Type Required
Name Codec name, have to match the codec name provided programmatically string true

Schema

Schema holds and defines actual type of the parent. It can either load type from the types provided programmatically, or by generating type using predefined primitive types.

Section Description Type Required
Name Schema name, needs to match one of the types provided programmatically string true unless DataType specified
DataType Primitive data type name enum: Int, Float, Float64, Bool, String, Date, Time true unless Name specified

Type

In some cases the Type definition can be provided in the yaml file, it allows to use them in templates but they will not be accessible programmatically. The usage for them might be f.e. parsing RequestBody to some struct.

Section Description Type Required
Name Type name string true
Fields Metadata fields descriptions []Field true

Field

Section Description Type Required Default
Name Struct field name string, UpperCamelCase true
Embed Indicates whether field should be Anonymous (i.e. while parsing JSON, if field is Anonymous and type of Struct the Struct will be flattened) bool false false
Column Database column name string true unless name doesn't match actual database column name
Schema Field schema Schema Schema or Fields need to be specified
Fields Describes non-primitive field type []Field Schema or Fields need to be specified ---

Template

In order to create more complex and optimized SQL statements, the velty syntax can be used to produce SQL dynamically based on the Parameters created based on f.e. http request.

Namespace:

  • Has - the parameter presence can be checked using the prefix $Has.
  • Unsafe - to access raw parameter value in the template, you can use prefix $Unsafe. This namespace should be used extremely careful. It should be used only for the parameters data_view Kind, or only to check value using velty statements. The parameters without $Unsafe prefix will be replaced with placeholders.
  • View - to access basic details about the current View in template, you can use $View prefix. Those values will be expanded as is. They will not be pushed as placeholders so it is important to wrap them with quotes.
Section Description Type Required Default
Source The actual SQL template string true
SourceURL Indicates whether field should be Anonymous (i.e. while parsing JSON, if field is Anonymous and type of Struct the Struct will be flattened) string false false
Schema The actual type holder of the combined parameters. Each parameter name and type has to match the current Schema Type Schema false false
PresenceSchema Similar to the Schema, but each Parameter name has to match field in the struct and every non primitive type has to be a boolean Schema false false
Parameters Parameters that can be used inside the template []Parameter false false

Connector

In order to communicate with database, database credentials need to be specified. To provide secure credentials store, the DSN should be represented using variables (i.e. ${user}:${password}) and expanded using external store.

Section Description Type Required
Name Connector name string true
Ref Other connector name which given connector should inherit from string false
Driver Database driver string true
DSN Database source name, the uri needed to connect to database. string true
Secret Secret true

Secret

Metrics

Used to collect data about View usage, including average time, success/failure ratio etc.

Section Description Type Required
URIPart string true

Logger

Programmatically created and provided logger.

Section Description Type Required
Ref Other Logger name which given Logger should inherit from string false
Name Logger name string true

Batch

Batches data fetched from database.

Section Description Type Required
Parent Number of parent placeholders in column in (?,?,?,?) statement if View is a child of any other View int false

CaseFormat

Enum, possible values:

  • uu, upperunderscore - i.e. EMPLOYEE_ID
  • lu, lowerunderscore - i.e. employee_id
  • uc, uppercamel - i.e. EmployeeId
  • lc, lowercamel - i.e. employeeId
  • l, lower - i.e. employeeid
  • u, upper - i.e. EMPLOYEEID

MatchStrategy

Enum, possible values:

  • read_matched
  • read_all

Parameters Codecs

Supported built in datly codecs:

  • VeltyCriteria - parses template using velocity syntax to sanitize criteria built from templates. Supported prefixes:
    • Unsafe - in order to access parameter values in the template, it is needed to use Unsafe prefix.
    • Safe_Column - if column with given parameter value doesn't exist the error will be thrown. i.e. $Safe_Column.Columns[$i].Name
    • Safe_Value - the parameter values with this prefix will be passed as binding parameters.
  • Strings - splits string using , into []string

Documentation

Index

Constants

View Source
const (
	FieldsQuery   = "_fields"
	OffsetQuery   = "_offset"
	LimitQuery    = "_limit"
	CriteriaQuery = "_criteria"
	OrderByQuery  = "_orderby"
	PageQuery     = "_page"
	ContentFormat = "_format"
	SyncFlag      = "viewSyncFlag"
)
View Source
const (
	//ResourceConnectors default connector resource name
	ResourceConnectors = "connectors"
	ResourceConstants  = "constants"
	ResourceMBus       = "mbus"
)
View Source
const (
	ModeExec        = Mode("SQLExec")
	ModeQuery       = Mode("SQLQuery")
	ModeUnspecified = Mode("")
	ModeHandler     = Mode("SQLHandler")

	AsyncJobsTable = "DATLY_JOBS"
	AsyncTagName   = "sqlxAsync"
)

Variables

View Source
var ContextKey = contextKey("view")

ContextKey view context key

View Source
var Now = time.Now
View Source
var (
	PingTimeInS = 15
)
View Source
var QueryStateParameters = &Config{
	LimitParameter:         &state.Parameter{Name: "Limit", In: state.NewQueryLocation(LimitQuery), Schema: state.NewSchema(xreflect.IntType)},
	OffsetParameter:        &state.Parameter{Name: "Offset", In: state.NewQueryLocation(OffsetQuery), Schema: state.NewSchema(xreflect.IntType)},
	PageParameter:          &state.Parameter{Name: "Page", In: state.NewQueryLocation(PageQuery), Schema: state.NewSchema(xreflect.IntType)},
	FieldsParameter:        &state.Parameter{Name: "Fields", In: state.NewQueryLocation(FieldsQuery), Schema: state.NewSchema(stringsType)},
	OrderByParameter:       &state.Parameter{Name: "OrderBy", In: state.NewQueryLocation(OrderByQuery), Schema: state.NewSchema(stringsType)},
	CriteriaParameter:      &state.Parameter{Name: "Criteria", In: state.NewQueryLocation(OrderByQuery), Schema: state.NewSchema(xreflect.StringType)},
	SyncFlagParameter:      &state.Parameter{Name: "SyncFlag", Cacheable: &trueValue, In: state.NewState(SyncFlag), Schema: state.NewSchema(boolType)},
	ContentFormatParameter: &state.Parameter{Name: "ContentFormat", In: state.NewQueryLocation(ContentFormat), Schema: state.NewSchema(xreflect.StringType)},
}

Functions

func AsViewParam added in v0.2.11

func AsViewParam(aView *View, aSelector *Statelet, batchData *BatchData, options ...interface{}) *expand.ViewContext

func BuildPresenceType added in v0.8.0

func BuildPresenceType(parameters []*state.Parameter) (reflect.Type, error)

func BuildTree added in v0.2.11

func BuildTree(schemaType reflect.Type, slice *xunsafe.Slice, nodes interface{}, reference *SelfReference, caseFormat text.CaseFormat) interface{}

func ColumnsSchema added in v0.8.0

func ColumnsSchema(caseFormat text.CaseFormat, columns []*Column, relations []*Relation, v *View, doc state.Documentation) func() (reflect.Type, error)

func ColumnsSchemaDocumented added in v0.8.0

func ColumnsSchemaDocumented(caseFormat text.CaseFormat, columns []*Column, relations []*Relation, v *View, doc state.Documentation) func() (reflect.Type, error)

func DefaultTypeName added in v0.8.0

func DefaultTypeName(name string) string

DefaultTypeName returns a default view type name

func Description added in v0.8.0

func Description(paramName, viewName string) string

func Evaluate added in v0.2.11

func Evaluate(evaluator *expand.Evaluator, options ...expand.StateOption) (*expand.State, error)

func ExpandWithFalseCondition added in v0.2.11

func ExpandWithFalseCondition(source string) string

func NewEvaluator added in v0.2.1

func NewEvaluator(parameters state.Parameters, stateType *structology.StateType, template string, typeLookup xreflect.LookupType, predicates []*expand.PredicateConfig) (*expand.Evaluator, error)

func NewMockSanitizer added in v0.2.11

func NewMockSanitizer() *expand.DataUnit

func ParamType added in v0.8.0

func ParamType(name string) reflect.Type

func ResetAerospikePool added in v0.2.7

func ResetAerospikePool()

func ResetConnectionConfig added in v0.2.11

func ResetConnectionConfig()

func ResetDBPool added in v0.2.7

func ResetDBPool()

func SummaryViewKey added in v0.8.0

func SummaryViewKey(ownerName, name string) string

SummaryViewKey returns template summary key

Types

type AerospikeConfig added in v0.8.0

type AerospikeConfig struct {
	SleepBetweenRetriesInMs int `json:",omitempty"`
	MaxRetries              int `json:",omitempty"`
	TotalTimeoutInMs        int `json:",omitempty"`
	SocketTimeoutInMs       int `json:",omitempty"`
	FailedRequestLimit      int `json:",omitempty"`
	ResetFailuresInMs       int `json:",omitempty"`
}

type Batch

type Batch struct {
	Size int `json:",omitempty"`
}

type BatchData added in v0.2.5

type BatchData struct {
	ColumnNames    []string
	Size           int
	ParentReadSize int

	Values      []interface{} //all values from parent
	ValuesBatch []interface{} //batched values defined view.Batch.Size
}

func (*BatchData) ColIn added in v0.8.0

func (b *BatchData) ColIn() []interface{}

func (*BatchData) ColInBatch added in v0.8.0

func (b *BatchData) ColInBatch() []interface{}

type Cache added in v0.2.2

type Cache struct {
	shared.Reference

	Name         string `json:",omitempty" yaml:",omitempty"`
	Location     string
	Provider     string
	TimeToLiveMs int
	PartSize     int `json:",omitempty"`
	AerospikeConfig
	Warmup *Warmup `json:",omitempty" yaml:",omitempty"`
	// contains filtered or unexported fields
}

func NewRefCache added in v0.8.0

func NewRefCache(name string) *Cache

NewRefCache creates cache reference

func (*Cache) GenerateCacheInput added in v0.2.11

func (c *Cache) GenerateCacheInput(ctx context.Context) ([]*CacheInput, error)

func (*Cache) NewInput added in v0.8.0

func (c *Cache) NewInput(selector *Statelet) *CacheInput

func (*Cache) Service added in v0.2.2

func (c *Cache) Service() (cache.Cache, error)

type CacheInput added in v0.2.11

type CacheInput struct {
	Selector   *Statelet
	Column     string
	MetaColumn string
	IndexMeta  bool
}

type CacheInputFn added in v0.2.11

type CacheInputFn func() ([]*CacheInput, error)

type CacheParameters added in v0.2.11

type CacheParameters struct {
	Set []*ParamValue
}

type Caches added in v0.8.0

type Caches []*Cache

func (*Caches) Append added in v0.8.0

func (r *Caches) Append(cache *Cache)

func (Caches) Has added in v0.8.0

func (c Caches) Has(name string) bool

func (Caches) Unique added in v0.8.0

func (c Caches) Unique() []*Cache

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{}, viewMetaHandler viewSummaryHandlerFn, readAll bool) *Collector

NewCollector creates a collector

func (*Collector) AddMeta added in v0.2.11

func (r *Collector) AddMeta(row interface{}) error

func (*Collector) Clone added in v0.8.0

func (r *Collector) Clone() *Collector

func (*Collector) Dest

func (r *Collector) Dest() interface{}

Project returns collector slice

func (*Collector) DestPtr added in v0.8.0

func (r *Collector) DestPtr() interface{}

Project returns collector slice ptr

func (*Collector) Fetched

func (r *Collector) Fetched()

func (*Collector) Len added in v0.2.7

func (r *Collector) Len() int

func (*Collector) Lock

func (r *Collector) Lock() *sync.Mutex

func (*Collector) MergeData

func (r *Collector) MergeData()

MergeData merges View with Collectors produced via Relations It is sufficient to call it on the most locators Collector to produce result

func (*Collector) NewItem

func (r *Collector) NewItem() func() interface{}

NewItem creates and return item provider

func (*Collector) OnSkip added in v0.2.11

func (r *Collector) OnSkip(_ []interface{}) error

func (*Collector) ParentPlaceholders

func (r *Collector) ParentPlaceholders() ([]interface{}, []string)

ParentPlaceholders if Collector doesn't support parallel fetching and has a locators, 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 locators 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) ReadAll added in v0.8.0

func (r *Collector) ReadAll() bool

ReadAll if Collector uses readAll flag, it means that his Relations can fetch all data View in the same time, (no matching parent data) Later on it will be merged with the parent Collector

func (*Collector) Relation

func (r *Collector) Relation() *Relation

func (*Collector) Relations

func (r *Collector) Relations(selector *Statelet) ([]*Collector, error)

Relations creates and register new Collector for each Relation present in the Template.Columns if View allows use Template.Columns

func (*Collector) Resolve

func (r *Collector) Resolve(column io.Column) func(ptr unsafe.Pointer) interface{}

Resolve resolved unmapped column

func (*Collector) SetDest added in v0.8.0

func (r *Collector) SetDest(dest interface{})

func (*Collector) Slice

func (r *Collector) Slice() (unsafe.Pointer, *xunsafe.Slice)

func (*Collector) View

func (r *Collector) View() *View

View returns View assigned to the Collector

func (*Collector) ViewMetaHandler added in v0.2.11

func (r *Collector) ViewMetaHandler(rel *Relation) (func(viewMeta interface{}) error, error)

func (*Collector) Visitor

func (r *Collector) Visitor(ctx context.Context) VisitorFn

VisitorFn creates visitor function

func (*Collector) WaitIfNeeded

func (r *Collector) WaitIfNeeded()

type Column

type Column struct {
	Name     string `json:",omitempty"`
	DataType string `json:",omitempty"`
	Tag      string `json:",omitempty"`

	Expression     string       `json:",omitempty"`
	Filterable     bool         `json:",omitempty"`
	Nullable       bool         `json:",omitempty"`
	Default        string       `json:",omitempty"`
	FormatTag      *format.Tag  `json:",omitempty"`
	Codec          *state.Codec `json:",omitempty"`
	DatabaseColumn string       `json:",omitempty"`
	IndexedBy      string       `json:",omitempty"`
	// contains filtered or unexported fields
}

Column represents View column

func NewColumn added in v0.8.0

func NewColumn(name, dataTypeName string, rType reflect.Type, nullable bool, opts ...ColumnOption) *Column

func (*Column) ApplyConfig added in v0.8.0

func (c *Column) ApplyConfig(config *ColumnConfig)

func (*Column) CaseFormat added in v0.8.0

func (c *Column) CaseFormat() text.CaseFormat

func (*Column) ColumnName

func (c *Column) ColumnName() string

ColumnName returns Column Name

func (*Column) ColumnType added in v0.2.1

func (c *Column) ColumnType() reflect.Type

func (*Column) EnsureFormatTag added in v0.8.0

func (c *Column) EnsureFormatTag()

func (*Column) EnsureType added in v0.8.0

func (c *Column) EnsureType(lookupType xreflect.LookupType) error

func (*Column) Field added in v0.8.0

func (c *Column) Field() *reflect.StructField

func (*Column) FieldName

func (c *Column) FieldName() string

func (*Column) Init

func (c *Column) Init(resource state.Resource, caseFormat text.CaseFormat, allowNulls bool) error

Init initializes Column

func (*Column) SetColumnType added in v0.8.0

func (c *Column) SetColumnType(rType reflect.Type)

func (*Column) SetField added in v0.8.0

func (c *Column) SetField(field reflect.StructField)

func (*Column) SqlExpression

func (c *Column) SqlExpression() string

SqlExpression builds column sql expression if any expression specified in format: Expression AS Name

func (*Column) TimeLayout added in v0.8.0

func (c *Column) TimeLayout() string

type ColumnConfig added in v0.2.2

type ColumnConfig struct {
	Name                string       `json:",omitempty"`
	IgnoreCaseFormatter *bool        `json:",omitempty"`
	Expression          *string      `json:",omitempty"`
	Codec               *state.Codec `json:",omitempty"`
	DataType            *string      `json:",omitempty"`
	Required            *bool        `json:",omitempty"`
	Format              *string      `json:",omitempty"`
	Tag                 *string      `json:",omitempty"`
	Default             *string      `json:",omitempty"`
}

func (*ColumnConfig) IgnoreColumn added in v0.9.1

func (c *ColumnConfig) IgnoreColumn() bool

type ColumnConfigs added in v0.8.0

type ColumnConfigs []*ColumnConfig

func (ColumnConfigs) Index added in v0.8.0

func (c ColumnConfigs) Index() NamedColumnConfig

type ColumnOption added in v0.8.0

type ColumnOption func(c *Column)

Column represents View column

func WithColumnTag added in v0.8.0

func WithColumnTag(tag string) ColumnOption

type Columns

type Columns []*Column

Columns wrap slice of Column

func NewColumns added in v0.8.0

func NewColumns(columns sqlparser.Columns) Columns

func (Columns) ApplyConfig added in v0.8.0

func (c Columns) ApplyConfig(configs map[string]*ColumnConfig, lookupType xreflect.LookupType) error

ApplyConfig applies column config

func (Columns) Dedupe added in v0.9.1

func (c Columns) Dedupe() Columns

func (Columns) Index added in v0.2.1

func (c Columns) Index(formatCase text.CaseFormat) NamedColumns

func (Columns) Init added in v0.2.1

func (c Columns) Init(resourcelet state.Resource, caseFormat text.CaseFormat, allowNulls bool) error

Init initializes each Column in the slice.

type Config

type Config struct {
	//TODO: Should order by be a slice?
	Namespace         string             `json:",omitempty"`
	OrderBy           string             `json:",omitempty"`
	Limit             int                `json:",omitempty"`
	NoLimit           bool               `json:",omitempty"`
	Constraints       *Constraints       `json:",omitempty"`
	Parameters        *SelectorParameter `json:",omitempty"`
	LimitParameter    *state.Parameter   `json:",omitempty"`
	OffsetParameter   *state.Parameter   `json:",omitempty"`
	PageParameter     *state.Parameter   `json:",omitempty"`
	FieldsParameter   *state.Parameter   `json:",omitempty"`
	OrderByParameter  *state.Parameter   `json:",omitempty"`
	CriteriaParameter *state.Parameter   `json:",omitempty"`

	//Settings parameters
	SyncFlagParameter      *state.Parameter `json:",omitempty"`
	ContentFormatParameter *state.Parameter `json:",omitempty"`
	// contains filtered or unexported fields
}

Config represent a View config selector

func (*Config) Clone added in v0.8.0

func (c *Config) Clone() *Config

func (*Config) CloneWithNs added in v0.8.0

func (c *Config) CloneWithNs(ctx context.Context, resource *Resource, owner *View, ns string) (*Config, error)

func (*Config) GetContentFormatParameter added in v0.8.0

func (c *Config) GetContentFormatParameter() *state.Parameter

func (*Config) GetSyncFlagParameter added in v0.8.0

func (c *Config) GetSyncFlagParameter() *state.Parameter

func (*Config) Init added in v0.2.1

func (c *Config) Init(ctx context.Context, resource *Resource, parent *View) error

type Connection added in v0.10.4

type Connection struct {
	DBConfig
	// contains filtered or unexported fields
}

Connector represents database/sql named connection config

func (*Connection) DB added in v0.10.4

func (c *Connection) DB() (*sql.DB, error)

DB creates connection to the DB. It is important to not close the DB since the connection is shared.

func (*Connection) Dialect added in v0.10.4

func (c *Connection) Dialect(ctx context.Context) (*info.Dialect, error)

func (*Connection) Init added in v0.10.4

func (c *Connection) Init(ctx context.Context, connectors Connectors) error

Init initializes connector. If Ref is specified, then Connector with the name has to be registered in Connectors

func (*Connection) Validate added in v0.10.4

func (c *Connection) Validate() error

Validate check if connector was configured properly. Name, Driver and DSN are required.

type Connector

type Connector struct {
	Connection
	Connections []*Connection
	// contains filtered or unexported fields
}

Connector represents database/sql named connection config

func DecodeConnectors added in v0.8.0

func DecodeConnectors(connectors []string) ([]*Connector, error)

DecodeConnectors decodes encoded connectors

func NewConnector added in v0.8.0

func NewConnector(name, driver, dsn string, opts ...ConnectorOption) *Connector

NewConnector creates a connector

func NewRefConnector added in v0.8.0

func NewRefConnector(name string) *Connector

NewRefConnector creates connection reference

func (*Connector) DB added in v0.2.7

func (c *Connector) DB() (*sql.DB, error)

func (*Connector) Dialect added in v0.8.0

func (c *Connector) Dialect(ctx context.Context) (*info.Dialect, error)

func (*Connector) GetConnection added in v0.10.4

func (c *Connector) GetConnection(ctx context.Context, connectors Connectors) (*Connection, error)

func (*Connector) Init

func (c *Connector) Init(ctx context.Context, connectors Connectors) error

func (*Connector) Validate

func (c *Connector) Validate() error

type ConnectorOption added in v0.8.0

type ConnectorOption func(c *Connector)

Connector represents database/sql named connection config

func WithDbConfig added in v0.8.0

func WithDbConfig(dbConfig *DBConfig) ConnectorOption

func WithSecret added in v0.8.0

func WithSecret(secret *scy.Resource) ConnectorOption

type ConnectorSlice

type ConnectorSlice []*Connector

ConnectorSlice represents NormalizeRepeated of *Connector

func (ConnectorSlice) Index

func (c ConnectorSlice) Index() Connectors

Views indexes Connectors by Connector.Name.

func (ConnectorSlice) IndexInto added in v0.8.0

func (c ConnectorSlice) IndexInto(result *Connectors)

func (ConnectorSlice) Init

func (c ConnectorSlice) Init(ctx context.Context, connectors Connectors) error

Init initializes each connector

type Connectors

type Connectors map[string]*Connector

Connectors represents Connector registry Paths 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
	Projection bool //enables columns projection from client (default ${NS}_fields= query param)
	Filterable []string
	SQLMethods []*Method `json:",omitempty"`

	Page *bool
	// contains filtered or unexported fields
}

Constraints configure what can be selected by Statelet For each _field, default value is `false`

func (*Constraints) IsPageEnabled added in v0.8.0

func (c *Constraints) IsPageEnabled() bool

func (*Constraints) SqlMethodsIndexed added in v0.2.1

func (c *Constraints) SqlMethodsIndexed() map[string]*Method

type CriteriaParam added in v0.2.11

type CriteriaParam struct {
	ColumnsIn             string `velty:"COLUMN_IN"`
	WhereClause           string `velty:"CRITERIA"`
	WhereClauseParameters []interface{}
	Pagination            string `velty:"PAGINATION"`
}

type DBConfig added in v0.2.7

type DBConfig struct {
	shared.Reference
	Name              string        `json:",omitempty"`
	Driver            string        `json:",omitempty"`
	DSN               string        `json:",omitempty"`
	MaxIdleConns      int           `json:",omitempty" yaml:",omitempty"`
	ConnMaxIdleTimeMs int           `json:",omitempty" yaml:",omitempty"`
	MaxOpenConns      int           `json:",omitempty" yaml:",omitempty"`
	ConnMaxLifetimeMs int           `json:",omitempty" yaml:",omitempty"`
	TimeoutTime       int           `json:",omitempty" yaml:",omitempty"`
	Secret            *scy.Resource `json:",omitempty"`
}

Connector represents database/sql named connection config

func (*DBConfig) ConnMaxIdleTime added in v0.2.7

func (c *DBConfig) ConnMaxIdleTime() time.Duration

ConnMaxIdleTime return connector max iddle time

func (*DBConfig) ConnMaxLifetime added in v0.2.7

func (c *DBConfig) ConnMaxLifetime() time.Duration

ConnMaxLifetime returns connector max lifetime

type Documentation added in v0.10.3

type Documentation struct {
	BaseURL     string
	URLs        []string
	*state.Docs `json:"-"`
}

func NewDocumentation added in v0.10.3

func NewDocumentation(URLS ...string) *Documentation

NewDocumentation creates a new documentation

func (*Documentation) Init added in v0.10.3

func (d *Documentation) Init(ctx context.Context, fs afs.Service, substitutes Substitutes) error

type EncodedConnector added in v0.8.0

type EncodedConnector string

EncodedConnector represents encoded connector

func (EncodedConnector) Decode added in v0.8.0

func (c EncodedConnector) Decode() (*Connector, error)

type ExpanderFn added in v0.2.11

type ExpanderFn func(placeholders *[]interface{}, SQL string, selector *Statelet, params CriteriaParam, batchData *BatchData, sanitized *expand.DataUnit) (string, error)

type Field

type Field struct {
	Name        string            `json:",omitempty"`
	Embed       bool              `json:",omitempty"`
	Column      string            `json:",omitempty"`
	FromName    string            `json:",omitempty"`
	Cardinality state.Cardinality `json:",omitempty"`
	Schema      *state.Schema     `json:",omitempty"`
	Fields      []*Field          `json:",omitempty"`
	Tag         string            `json:",omitempty"`
	Ptr         bool
	Description string
	Example     string
}

func (*Field) Init

func (f *Field) Init(ctx context.Context, typeLookup xreflect.LookupType, d *TypeDefinition) error
type Link struct {
	Namespace     string
	Column        string
	Field         string
	IncludeColumn *bool
	// contains filtered or unexported fields
}
func WithLink(field, column string) *Link

WithLink returns a link

func (*Link) EncodeLinkTag added in v0.8.0

func (l *Link) EncodeLinkTag() string

func (*Link) Init added in v0.8.0

func (l *Link) Init()

func (*Link) Validate added in v0.8.0

func (l *Link) Validate() error
type Links []*Link

func JoinOn added in v0.8.0

func JoinOn(links ...*Link) Links

JoinOn returns links

func (Links) InColumnExpression added in v0.8.0

func (l Links) InColumnExpression() []string

func (Links) Init added in v0.8.0

func (l Links) Init(name string, v *View) error

func (Links) Namespace added in v0.8.0

func (l Links) Namespace() string

func (Links) Validate added in v0.8.0

func (l Links) Validate() error

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) ReadAll added in v0.8.0

func (s MatchStrategy) ReadAll() bool

ReadAll indicates whether MatchStrategy support parallel read.

func (MatchStrategy) Validate

func (s MatchStrategy) Validate() error

Validate checks if MatchStrategy is valid

type MessageBusSlice added in v0.8.0

type MessageBusSlice []*mbus.Resource

func (MessageBusSlice) Index added in v0.8.0

func (m MessageBusSlice) Index() MessageBuses

type MessageBuses added in v0.8.0

type MessageBuses map[string]*mbus.Resource

MessageBuses message bus map

func (MessageBuses) Lookup added in v0.8.0

func (m MessageBuses) Lookup(name string) (*mbus.Resource, error)

Lookup returns message bus for supplied name or error

type MetaKind added in v0.8.0

type MetaKind string
const (
	MetaKindRecord MetaKind = "record"
	MetaKindHeader MetaKind = "header"
)

type Method added in v0.2.1

type Method struct {
	Name string          `json:",omitempty"`
	Args []*state.Schema `json:",omitempty"`
}

type Metrics

type Metrics struct {
	*gmetric.Service
	Method string
}

Metrics represents a view metrics

type Mode added in v0.2.11

type Mode string

type NamedColumnConfig added in v0.8.0

type NamedColumnConfig map[string]*ColumnConfig

type NamedColumns added in v0.8.0

type NamedColumns map[string]*Column

NamedColumns represents *Column registry.

func (NamedColumns) Column added in v0.8.0

func (c NamedColumns) Column(name string) (codec.Column, bool)

func (NamedColumns) ColumnName added in v0.8.0

func (c NamedColumns) ColumnName(key string) (string, error)

func (NamedColumns) Lookup added in v0.8.0

func (c NamedColumns) Lookup(name string) (*Column, error)

Lookup returns Column with given name.

func (NamedColumns) Register added in v0.8.0

func (c NamedColumns) Register(caseFormat text.CaseFormat, column *Column)

Register registers *Column

func (NamedColumns) RegisterHolder added in v0.8.0

func (c NamedColumns) RegisterHolder(columnName, holder string) error

RegisterHolder looks for the Column by Relation.Column name. If it finds registers that Column with Relation.Holder key.

func (NamedColumns) RegisterWithName added in v0.8.0

func (c NamedColumns) RegisterWithName(name string, column *Column)

type NamedResources added in v0.8.0

type NamedResources map[string]*Resource

Resource represents grouped View needed to build the View can be loaded from i.e. yaml file

type NamedViews added in v0.8.0

type NamedViews map[string]*View

NamedViews represents views registry indexed by View name.

func (NamedViews) Lookup added in v0.8.0

func (v NamedViews) Lookup(viewName string) (*View, error)

Lookup returns View by given name or error if View is not present.

func (*NamedViews) Register added in v0.8.0

func (v *NamedViews) Register(view *View)

Register registers View in registry using View name.

type Names

type Names []string

Names represents columns names slice.

func (Names) Index

func (c Names) Index() map[string]bool

Indexm creates column map.

type NamespaceView added in v0.8.0

type NamespaceView struct {
	View       *View
	Path       string
	Root       bool
	Namespaces []string
}

func (*NamespaceView) SelectorParameters added in v0.8.0

func (n *NamespaceView) SelectorParameters(parameter *state.Parameter, rootParameter *state.Parameter) []*state.Parameter

type NamespacedView added in v0.8.0

type NamespacedView struct {
	Views []*NamespaceView
	// contains filtered or unexported fields
}

func IndexViews added in v0.8.0

func IndexViews(aView *View, holder string) *NamespacedView

IndexViews indexes views

func (*NamespacedView) ByName added in v0.8.0

func (n *NamespacedView) ByName(ns string) *NamespaceView

func (*NamespacedView) ByNamespace added in v0.8.0

func (n *NamespacedView) ByNamespace(ns string) *NamespaceView

func (*NamespacedView) Parameters added in v0.8.0

func (n *NamespacedView) Parameters() state.NamedParameters

type NodeIndex added in v0.2.11

type NodeIndex map[interface{}]map[interface{}]bool

func (NodeIndex) Get added in v0.2.11

func (i NodeIndex) Get(id interface{}) map[interface{}]bool

type Option

type Option func(v *View) error

Option defines a view option

func WithBatchSize added in v0.8.0

func WithBatchSize(size int) Option

WithBatchSize creates an Option to set batchSize

func WithColumns added in v0.8.0

func WithColumns(columns Columns) Option

func WithConnector added in v0.8.0

func WithConnector(connector *Connector) Option

WithConnector creates connector View option

func WithConnectorRef added in v0.8.0

func WithConnectorRef(ref string) Option

WithConnectorRef creates connector View option

func WithCriteria added in v0.8.0

func WithCriteria(columns ...string) Option

WithCriteria creates criteria constraints View option

func WithDBConfig added in v0.8.0

func WithDBConfig(dbConfig *DBConfig) Option

WithDBConfig creates connector View option

func WithFS added in v0.8.0

func WithFS(fs *embed.FS) Option

WithFS creates fs options

func WithFSEmbedder added in v0.10.1

func WithFSEmbedder(embeder *state.FSEmbedder) Option

WithFSEmbedder creates fs options

func WithLimit added in v0.8.0

func WithLimit(limit *int) Option

func WithMatchStrategy added in v0.8.0

func WithMatchStrategy(match string) Option

WithMatchStrategy creates an Option to set MatchStrategy

func WithMode added in v0.8.0

func WithMode(mode Mode) Option

WithMode creates mode View option

func WithOneToMany added in v0.8.0

func WithOneToMany(holder string, on Links, ref *ReferenceView, opts ...RelationOption) Option

WithOneToMany creates to many relation View option

func WithOneToOne added in v0.8.0

func WithOneToOne(holder string, on Links, ref *ReferenceView, opts ...RelationOption) Option

WithOneToOne creates to one relation View option

func WithPartitioned added in v0.8.0

func WithPartitioned(partitioned *Partitioned) Option

func WithReinitialize added in v0.8.0

func WithReinitialize() Option

func WithResource added in v0.8.0

func WithResource(resource state.Resource) Option

WithResource creates resource View option

func WithSQL added in v0.8.0

func WithSQL(SQL string, parameters ...*state.Parameter) Option

WithSQL creates SQL FROM View option

func WithSchema added in v0.8.0

func WithSchema(schema *state.Schema) Option

WithSchema creates connector View option

func WithStructTag added in v0.8.0

func WithStructTag(tag reflect.StructTag, fs *embed.FS) Option

WithStructTag creates tag options

func WithTag added in v0.8.0

func WithTag(aTag *tags.Tag) Option

WithFS creates tag options

func WithTemplate added in v0.8.0

func WithTemplate(template *Template) Option

WithTemplate creates connector View option

func WithTransforms added in v0.8.0

func WithTransforms(transforms marshal.Transforms) Option

func WithViewKind added in v0.8.0

func WithViewKind(mode Mode) Option

func WithViewTag added in v0.9.1

func WithViewTag(tag string) Option

WithViewTag creates an Option to set tag

func WithViewType added in v0.8.0

func WithViewType(t reflect.Type, options ...state.SchemaOption) Option

WithViewType creates schema type View option

type Options added in v0.8.0

type Options []Option

Options defines a view options

func (Options) Apply added in v0.8.0

func (o Options) Apply(aView *View) error

Apply applies option

type PackagedType added in v0.8.0

type PackagedType struct {
	Package string
	Name    string
	reflect.Type
}

PackagedType represtns a package type

func NewPackagedType added in v0.8.0

func NewPackagedType(pkg string, name string, t reflect.Type) *PackagedType

func (*PackagedType) TypeName added in v0.8.0

func (p *PackagedType) TypeName() string

TypeName returns type name

type ParamValue added in v0.2.11

type ParamValue struct {
	Name   string
	Values []interface{}
	// contains filtered or unexported fields
}

type Partitioned added in v0.8.0

type Partitioned struct {
	DataType    string
	Arguments   []string
	Concurrency int
	// contains filtered or unexported fields
}

Partitioned represents a partitioned view

func NewPartitioned added in v0.8.0

func NewPartitioned(paritioner Partitioner, concurrency int, args ...string) *Partitioned

NewPartitioned creates a new partitioned view

func (*Partitioned) Partitioner added in v0.8.0

func (p *Partitioned) Partitioner() Partitioner

Partitioner returns the partitioner

func (*Partitioned) SetPartitioner added in v0.8.0

func (p *Partitioned) SetPartitioner(partitioner Partitioner)

SetPartitioner sets the partitioner

type Partitioner added in v0.8.0

type Partitioner interface {
	Partitions(ctx context.Context, db *sql.DB, aView *View) *Partitions
}

Partitioner represents a partitioner

type Partitions added in v0.8.0

type Partitions struct {
	Table      string
	Expression string
	Partitions [][]interface{}
	Partition  []interface{}
}

Partitions represents a partitioned view

type PredicateEvaluator added in v0.8.0

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

func (*PredicateEvaluator) Compute added in v0.8.0

func (e *PredicateEvaluator) Compute(ctx context.Context, value interface{}) (*codec.Criteria, error)

func (*PredicateEvaluator) Evaluate added in v0.8.0

func (e *PredicateEvaluator) Evaluate(ctx *expand.Context, state *structology.State, value interface{}) (*expand.State, error)

type QuerySelector added in v0.8.0

type QuerySelector struct {
	//SELECTORS
	DatabaseFormat text.CaseFormat
	OutputFormat   text.CaseFormat
	Columns        []string `json:",omitempty"`
	Fields         []string `json:",omitempty"`
	OrderBy        string   `json:",omitempty"`
	Offset         int      `json:",omitempty"`
	Limit          int      `json:",omitempty"`

	Criteria     string        `json:",omitempty"`
	Placeholders []interface{} `json:",omitempty"`
	Page         int
	Ignore       bool
	predicate.Filters
	// contains filtered or unexported fields
}

Statelet allows customizing View fetched from Database

func (*QuerySelector) Add added in v0.8.0

func (s *QuerySelector) Add(fieldName string, isHolder bool)

func (*QuerySelector) CurrentLimit added in v0.8.0

func (s *QuerySelector) CurrentLimit() int

func (*QuerySelector) CurrentOffset added in v0.8.0

func (s *QuerySelector) CurrentOffset() int

func (*QuerySelector) CurrentPage added in v0.8.0

func (s *QuerySelector) CurrentPage() int

func (*QuerySelector) Has added in v0.8.0

func (s *QuerySelector) Has(field string) bool

Has checks if Field is present in Template.Columns

func (*QuerySelector) SetCriteria added in v0.8.0

func (s *QuerySelector) SetCriteria(expanded string, placeholders []interface{})

type QuerySettings added in v0.8.0

type QuerySettings struct {
	//SETTINGS
	SyncFlag      bool
	ContentFormat string
}

Statelet allows customizing View fetched from Database

type Reducer added in v0.8.0

type Reducer interface {
	Reduce(slice interface{}) interface{}
}

Reducer represents a reducer

type ReducerProvider added in v0.8.0

type ReducerProvider interface {
	Reducer(ctx context.Context) Reducer
}

ReducerProvider represents a reducer provider

type ReferenceView

type ReferenceView struct {
	View // event type
	//Link
	On Links `json:",omitempty"`
}

ReferenceView represents referenced View In our example it would be Account

func NewReferenceView added in v0.8.0

func NewReferenceView(links Links, view *View) *ReferenceView

NewReferenceView creates a reference View

func (*ReferenceView) Init

func (r *ReferenceView) Init(_ context.Context, aView *View) (err 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"`
	Caser         text.CaseFormat   `json:",omitempty"`
	Cardinality   state.Cardinality `json:",omitempty"` //IsToOne, or Many
	On            Links
	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: locators View represents Employee{AccountId: int}, Relation represents Account{Id: int} We want to create result like: Employee{Account{Id:int}}

func (*Relation) Init

func (r *Relation) Init(ctx context.Context, parent *View) error

Init initializes Relation

func (r *Relation) TagLink() tags.LinkOn

func (*Relation) Validate

func (r *Relation) Validate() error

Validate checks if Relation is valid

type RelationOption added in v0.8.0

type RelationOption func(r *Relation)

RelationOption defines relation options

type RelationsSlice

type RelationsSlice []*Relation

RelationsSlice represents slice of Relation

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"`

	CacheProviders []*Cache

	Connectors []*Connector

	MessageBuses []*mbus.Resource

	Views Views `json:",omitempty"`

	Parameters state.Parameters `json:",omitempty"`

	Types []*TypeDefinition

	Loggers logger.Adapters `json:",omitempty"`

	Predicates []*predicate.Template

	Substitutes Substitutes
	Docs        *Documentation
	FSEmbedder  *state.FSEmbedder
	// 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

func LoadResourceFromURL(ctx context.Context, URL string, fs afs.Service) (*Resource, error)

LoadResourceFromURL load resource from URL

func NewResource

func NewResource(parent *xreflect.Types) *Resource

NewResource creates a Resource and register provided Types

func NewResourceFromURL

func NewResourceFromURL(ctx context.Context, url string, types *xreflect.Types, codecs *codec.Registry) (*Resource, error)

NewResourceFromURL loads and initializes Resource from file .yaml

func (*Resource) AddConnector added in v0.8.0

func (r *Resource) AddConnector(name string, driver string, dsn string, opts ...ConnectorOption) *Connector

AddConnector adds connector

func (*Resource) AddConnectors

func (r *Resource) AddConnectors(connectors ...*Connector)

AddConnectors register connectors in the resource

func (*Resource) AddLoggers

func (r *Resource) AddLoggers(loggers ...*logger.Adapter)

AddLoggers register loggers in the resource

func (*Resource) AddMessageBus added in v0.8.0

func (r *Resource) AddMessageBus(messageBuses ...*mbus.Resource)

func (*Resource) AddParameters

func (r *Resource) AddParameters(parameters ...*state.Parameter)

AddParameters register parameters in the resource

func (*Resource) AddViews

func (r *Resource) AddViews(views ...*View)

AddViews register views in the resource

func (*Resource) CacheProvider added in v0.2.7

func (r *Resource) CacheProvider(ref string) (*Cache, bool)

func (*Resource) CodecByName added in v0.8.0

func (r *Resource) CodecByName(name string) (*codec.Codec, bool)

func (*Resource) Connector added in v0.8.0

func (r *Resource) Connector(name string) (*Connector, error)

func (*Resource) ConnectorByName

func (r *Resource) ConnectorByName() Connectors

func (*Resource) Doc added in v0.8.0

func (r *Resource) Doc() (docs.Service, bool)

func (*Resource) ExistsConnector added in v0.8.0

func (r *Resource) ExistsConnector(name string) bool

func (*Resource) ExpandSubstitutes added in v0.9.10

func (r *Resource) ExpandSubstitutes(text string) string

func (*Resource) FindConnector

func (r *Resource) FindConnector(view *View) (*Connector, error)

func (*Resource) GetConnectors

func (r *Resource) GetConnectors() Connectors

GetConnectors returns Connectors supplied with the Resource

func (*Resource) GetViews

func (r *Resource) GetViews() NamedViews

GetViews returns NamedViews supplied with the Resource

func (*Resource) IndexViews added in v0.8.0

func (r *Resource) IndexViews()

func (*Resource) Init

func (r *Resource) Init(ctx context.Context, options ...interface{}) error

Init initializes Resource

func (*Resource) LoadObject added in v0.2.1

func (r *Resource) LoadObject(ctx context.Context, URL string) (storage.Object, error)

func (*Resource) LoadText

func (r *Resource) LoadText(ctx context.Context, URL string) (string, error)

func (*Resource) Lock added in v0.9.10

func (r *Resource) Lock()

func (*Resource) LookupParameter added in v0.8.0

func (r *Resource) LookupParameter(name string) (*state.Parameter, error)

func (*Resource) LookupType added in v0.8.0

func (r *Resource) LookupType() xreflect.LookupType

func (*Resource) MBusResourceByName added in v0.8.10

func (r *Resource) MBusResourceByName() MessageBuses

func (*Resource) MergeFrom

func (r *Resource) MergeFrom(resource *Resource, types *xreflect.Types)

func (*Resource) MessageBus added in v0.8.0

func (r *Resource) MessageBus(name string) (*mbus.Resource, error)

func (*Resource) ModTime added in v0.2.1

func (r *Resource) ModTime() time.Time

func (*Resource) NamedParameters added in v0.8.0

func (r *Resource) NamedParameters() state.NamedParameters

func (*Resource) ParamByName added in v0.8.0

func (r *Resource) ParamByName(name string) (*state.Parameter, error)

func (*Resource) RepositoryURL added in v0.10.3

func (r *Resource) RepositoryURL() string

func (*Resource) ReverseSubstitutes added in v0.9.10

func (r *Resource) ReverseSubstitutes(text string) string

func (*Resource) SetCodecs added in v0.8.0

func (r *Resource) SetCodecs(codecs *codec.Registry)

func (*Resource) SetFs added in v0.8.0

func (r *Resource) SetFs(fs afs.Service)

func (*Resource) SetTypes

func (r *Resource) SetTypes(types *xreflect.Types)

func (*Resource) TypeName added in v0.2.1

func (r *Resource) TypeName(t reflect.Type) (string, bool)

func (*Resource) TypeRegistry added in v0.8.0

func (r *Resource) TypeRegistry() *xreflect.Types

func (*Resource) Unlock added in v0.9.10

func (r *Resource) Unlock()

func (*Resource) UpdateTime added in v0.9.12

func (r *Resource) UpdateTime(ctx context.Context, URL string) error

func (*Resource) View

func (r *Resource) View(name string) (*View, error)

View returns View with given name

func (*Resource) ViewSchema added in v0.8.0

func (r *Resource) ViewSchema(ctx context.Context, name string) (*state.Schema, error)

func (*Resource) ViewSchemaPointer added in v0.9.0

func (r *Resource) ViewSchemaPointer(ctx context.Context, name string) (*state.Schema, error)

type ResourceOptions added in v0.8.0

type ResourceOptions struct {
	Codecs          *codec.Registry
	Columns         map[string]Columns
	Types           *xreflect.Types
	TransformsIndex marshal.TransformIndex
	Predicates      *extension.PredicateRegistry
	Docs            *docs.Registry
	Metrics         *Metrics
}

Resource represents grouped View needed to build the View can be loaded from i.e. yaml file

type Resourcelet added in v0.8.0

type Resourcelet struct {
	*View
	*Resource
}

func NewResources added in v0.8.0

func NewResources(resource *Resource, view *View) *Resourcelet

func (*Resourcelet) AppendParameter added in v0.8.0

func (r *Resourcelet) AppendParameter(parameter *state.Parameter)

func (*Resourcelet) CodecOptions added in v0.8.0

func (r *Resourcelet) CodecOptions() *codec.Options

func (*Resourcelet) Codecs added in v0.8.0

func (r *Resourcelet) Codecs() *codec.Registry

func (Resourcelet) IndexedColumns added in v0.8.0

func (r Resourcelet) IndexedColumns() NamedColumns

func (*Resourcelet) LookupParameter added in v0.8.0

func (r *Resourcelet) LookupParameter(name string) (*state.Parameter, error)

type SelectorParameter added in v0.2.11

type SelectorParameter struct {
	Limit    string `json:",omitempty"`
	Offset   string `json:",omitempty"`
	Page     string `json:",omitempty"`
	Fields   string `json:",omitempty"`
	OrderBy  string `json:",omitempty"`
	Criteria string `json:",omitempty"`
	SyncFlag string `json:",omitempty"`
}

Config represent a View config selector

type SelfReference added in v0.2.11

type SelfReference struct {
	Holder string
	Parent string
	Child  string
}

type State added in v0.8.0

type State struct {
	Views map[string]*Statelet
	sync.RWMutex
}

State represents view statelet registry

func NewState added in v0.8.0

func NewState() *State

NewState creates a selector

func (*State) Init added in v0.8.0

func (s *State) Init(aView *View)

Init initializes each Statelet

func (*State) Lookup added in v0.8.0

func (s *State) Lookup(view *View) *Statelet

Lookup returns and initializes Statelet attached to View. Creates new one if doesn't exist.

func (*State) QuerySelector added in v0.8.0

func (s *State) QuerySelector(view *View) *QuerySelector

QuerySelector returns query selector

func (*State) QuerySettings added in v0.8.0

func (s *State) QuerySettings(view *View) *QuerySettings

QuerySettings returns query settings

type Statelet added in v0.8.0

type Statelet struct {
	Template *structology.State
	QuerySelector
	QuerySettings
}

InputType represents view state

func NewStatelet added in v0.8.0

func NewStatelet() *Statelet

NewStatelet creates a selector

func (*Statelet) IgnoreRead added in v0.8.0

func (s *Statelet) IgnoreRead()

func (*Statelet) Init added in v0.8.0

func (s *Statelet) Init(aView *View)

Init initializes Statelet

type Substitutes added in v0.8.0

type Substitutes map[string]string

func (Substitutes) Keys added in v0.8.0

func (s Substitutes) Keys() []string

func (Substitutes) Replace added in v0.8.0

func (s Substitutes) Replace(text string) string

func (Substitutes) ReverseReplace added in v0.8.0

func (s Substitutes) ReverseReplace(text string) string

type Template

type Template struct {
	Source    string        `json:",omitempty" yaml:"source,omitempty"`
	SourceURL string        `json:",omitempty" yaml:"sourceURL,omitempty"`
	Schema    *state.Schema `json:",omitempty" yaml:"schema,omitempty"`

	Parameters state.Parameters `json:",omitempty" yaml:"parameters,omitempty"`
	Summary    *TemplateSummary `json:",omitempty" yaml:",omitempty"`
	// contains filtered or unexported fields
}

func NewTemplate added in v0.8.0

func NewTemplate(source string, opts ...TemplateOption) *Template

NewTemplate creates a template

func (*Template) EvaluateSource

func (t *Template) EvaluateSource(parameterState *structology.State, parentParam *expand.ViewContext, batchData *BatchData, options ...interface{}) (*expand.State, error)

func (*Template) EvaluateState added in v0.8.0

func (t *Template) EvaluateState(parameterState *structology.State, parentParam *expand.ViewContext, batchData *BatchData, options ...interface{}) (*expand.State, error)

func (*Template) EvaluateStateWithSession added in v0.8.0

func (t *Template) EvaluateStateWithSession(parameterState *structology.State, parentParam *expand.ViewContext, batchData *BatchData, sess *extension.Session, options ...interface{}) (*expand.State, error)

func (*Template) EvaluatorStateType added in v0.8.0

func (t *Template) EvaluatorStateType() reflect.Type

func (*Template) Expand added in v0.2.5

func (t *Template) Expand(placeholders *[]interface{}, SQL string, selector *Statelet, params CriteriaParam, batchData *BatchData, sanitized *expand.DataUnit) (string, error)

func (*Template) Init

func (t *Template) Init(ctx context.Context, resource *Resource, view *View) error

func (*Template) IsActualTemplate added in v0.2.1

func (t *Template) IsActualTemplate() bool

func (*Template) Package added in v0.8.0

func (t *Template) Package() string

func (*Template) StateType added in v0.8.0

func (t *Template) StateType() *structology.StateType

type TemplateEvaluation added in v0.2.11

type TemplateEvaluation struct {
	SQL       string
	Evaluated bool
	Expander  ExpanderFn
	Args      []interface{}
}

type TemplateOption added in v0.8.0

type TemplateOption func(t *Template)

func WithTemplateParameters added in v0.8.0

func WithTemplateParameters(parameters ...*state.Parameter) TemplateOption

WithTemplateParameters return parameter template options

func WithTemplateSchema added in v0.8.0

func WithTemplateSchema(schema *state.Schema) TemplateOption

WithTemplateSchema returns with template schema

type TemplateSummary added in v0.8.0

type TemplateSummary struct {
	SourceURL   string
	Source      string
	Name        string
	Kind        MetaKind
	Cardinality state.Cardinality
	Columns     Columns

	Schema *state.Schema
	// contains filtered or unexported fields
}

func (*TemplateSummary) EnsureSchema added in v0.8.0

func (m *TemplateSummary) EnsureSchema()

func (*TemplateSummary) Evaluate added in v0.8.0

func (m *TemplateSummary) Evaluate(parameterState *structology.State, viewParam *expand.ViewContext) (string, []interface{}, error)

func (*TemplateSummary) Init added in v0.8.0

func (m *TemplateSummary) Init(ctx context.Context, owner *Template, resource *Resource) error

type TypeDefinition added in v0.8.0

type TypeDefinition struct {
	shared.Reference `json:",omitempty" `
	Name             string   `json:",omitempty" yaml:"Name" `
	Alias            string   `json:",omitempty"`
	Fields           []*Field `json:",omitempty"`

	Schema      *state.Schema     `json:",omitempty"`
	DataType    string            `json:",omitempty"  yaml:"DataType" `
	Cardinality state.Cardinality `json:",omitempty"  yaml:"Cardinality" `
	Package     string            `json:",omitempty"  yaml:"Package" `
	ModulePath  string            `json:",omitempty"  yaml:"ModulePath" `
	Ptr         bool              `json:",omitempty" yaml:"Ptr" `
	CustomType  bool              `json:",omitempty"`
	// contains filtered or unexported fields
}

func (*TypeDefinition) AddField added in v0.8.0

func (d *TypeDefinition) AddField(field *Field)

func (*TypeDefinition) Init added in v0.8.0

func (d *TypeDefinition) Init(ctx context.Context, lookupType xreflect.LookupType) error

func (TypeDefinition) SimplePackage added in v0.9.0

func (d TypeDefinition) SimplePackage() string

func (*TypeDefinition) Type added in v0.8.0

func (d *TypeDefinition) Type() reflect.Type

func (*TypeDefinition) TypeName added in v0.8.0

func (d *TypeDefinition) TypeName() string

type TypeDefinitions added in v0.8.0

type TypeDefinitions []*TypeDefinition

func (TypeDefinitions) Exclude added in v0.8.0

func (d TypeDefinitions) Exclude(candidates ...string) TypeDefinitions

type View

type View struct {
	shared.Reference
	Mode        Mode       `json:",omitempty"`
	Connector   *Connector `json:",omitempty"`
	Standalone  bool       `json:",omitempty"`
	Name        string     `json:",omitempty"`
	Description string     `json:",omitempty"`
	Module      string     `json:",omitempty"`
	Alias       string     `json:",omitempty"`
	Table       string     `json:",omitempty"`
	From        string     `json:",omitempty"`
	FromURL     string     `json:",omitempty"`
	Exclude     []string   `json:",omitempty"`
	Columns     []*Column  `json:",omitempty"`
	TypeName    string     `json:",omitempty"`
	Tag         string     `json:",omitempty"`
	Partitioned *Partitioned
	Criteria    string `json:",omitempty"`

	Selector *Config   `json:",omitempty"`
	Template *Template `json:",omitempty"`

	Schema *state.Schema `json:",omitempty"`

	With []*Relation `json:",omitempty"`

	MatchStrategy MatchStrategy `json:",omitempty"`
	Batch         *Batch        `json:",omitempty"`

	Logger     *logger.Adapter `json:",omitempty"`
	Counter    logger.Counter  `json:"-"`
	CaseFormat text.CaseFormat `json:",omitempty"`

	DiscoverCriteria *bool  `json:",omitempty"`
	AllowNulls       *bool  `json:",omitempty"`
	Cache            *Cache `json:",omitempty"`

	ColumnsConfig map[string]*ColumnConfig `json:",omitempty"`
	SelfReference *SelfReference           `json:",omitempty"`

	TableBatches map[string]bool `json:",omitempty"`
	// contains filtered or unexported fields
}

View represents a View

func Context added in v0.8.0

func Context(ctx context.Context) *View

func New added in v0.8.0

func New(name, table string, opts ...Option) (*View, error)

New creates a View

func NewExecView added in v0.8.0

func NewExecView(name, table string, template string, parameters []*state.Parameter, opts ...Option) *View

NewExecView creates an execution View

func NewRefView added in v0.8.0

func NewRefView(ref string) *View

func NewView added in v0.8.0

func NewView(name, table string, opts ...Option) *View

NewView creates a View

func (*View) AreNullValuesAllowed added in v0.2.11

func (v *View) AreNullValuesAllowed() bool

func (*View) BuildParametrizedSQL added in v0.8.0

func (v *View) BuildParametrizedSQL(aState state.Parameters, types *xreflect.Types, SQL string, bindingArgs []interface{}, options ...expand2.StateOption) (*sqlx.SQL, error)

func (*View) CanUseSelectorCriteria

func (v *View) CanUseSelectorCriteria() bool

CanUseSelectorCriteria indicates if Template.Criteria can be used

func (*View) CanUseSelectorLimit

func (v *View) CanUseSelectorLimit() bool

CanUseSelectorLimit indicates if Template.Limit can be used

func (*View) CanUseSelectorOffset

func (v *View) CanUseSelectorOffset() bool

CanUseSelectorOffset indicates if Template.Offset can be used

func (*View) CanUseSelectorOrderBy

func (v *View) CanUseSelectorOrderBy() bool

CanUseSelectorOrderBy indicates if Template.OrderBy can be used

func (*View) CanUseSelectorProjection added in v0.2.2

func (v *View) CanUseSelectorProjection() bool

CanUseSelectorProjection indicates if Template.Fields can be used

func (*View) Collector

func (v *View) Collector(dest interface{}, handleMeta viewSummaryHandlerFn, supportParallel bool) *Collector

Collector creates new Collector for View.DataType

func (*View) ColumnByName

func (v *View) ColumnByName(name string) (*Column, bool)

ColumnByName returns Column by Column.Name

func (*View) ComponentType added in v0.8.0

func (v *View) ComponentType() reflect.Type

func (*View) Context added in v0.8.0

func (v *View) Context(ctx context.Context) context.Context

func (*View) DBProvider added in v0.9.9

func (v *View) DBProvider(name string) (*sql.DB, error)

func (*View) DataType

func (v *View) DataType() reflect.Type

DataType returns struct type.

func (*View) DatabaseType added in v0.2.2

func (v *View) DatabaseType() reflect.Type

func (*View) Db

func (v *View) Db() (*sql.DB, error)

Db returns database connection that View was assigned to.

func (*View) EnsureTemplate added in v0.8.0

func (v *View) EnsureTemplate()

func (*View) Expand added in v0.2.5

func (v *View) Expand(placeholders *[]interface{}, SQL string, selector *Statelet, params CriteriaParam, batchData *BatchData, sanitized *expand2.DataUnit) (string, error)

func (*View) GetResource added in v0.8.0

func (v *View) GetResource() *Resource

func (*View) GetSchema added in v0.8.0

func (v *View) GetSchema(ctx context.Context) (*state.Schema, error)

func (*View) IndexedColumns

func (v *View) IndexedColumns() NamedColumns

IndexedColumns returns Columns

func (*View) Init

func (v *View) Init(ctx context.Context, resource *Resource, opts ...Option) error

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) InputParameters added in v0.8.0

func (v *View) InputParameters() state.Parameters

func (*View) IsHolder

func (v *View) IsHolder(value string) bool

func (*View) LookupRelation added in v0.8.0

func (v *View) LookupRelation(name string) (*Relation, error)

func (*View) MetaTemplateEnabled added in v0.2.11

func (v *View) MetaTemplateEnabled() bool

func (*View) OutputType added in v0.8.0

func (v *View) OutputType() reflect.Type

OutputType returns reader view output type

func (*View) ParamByName added in v0.2.11

func (v *View) ParamByName(name string) (*state.Parameter, error)

func (*View) Resource added in v0.8.0

func (v *View) Resource() state.Resource

func (*View) ResultLimit added in v0.8.0

func (v *View) ResultLimit() int

func (*View) SetNamedType added in v0.8.0

func (v *View) SetNamedType(aType reflect.Type)

func (*View) SetParameter added in v0.8.0

func (v *View) SetParameter(name string, selectors *State, value interface{}) error

SetParameter sets a View or relation parameter, for relation name has to be prefixed relName:paramName

func (*View) SetResource added in v0.8.0

func (v *View) SetResource(resource *Resource)

func (*View) ShouldTryDiscover added in v0.2.1

func (v *View) ShouldTryDiscover() bool

func (*View) Source

func (v *View) Source() string

Source returns database View source. It prioritizes From, Table then View.Name

func (*View) TableAlias added in v0.8.0

func (v *View) TableAlias() string

func (*View) TableName added in v0.8.0

func (v *View) TableName() string

func (*View) TypeDefinitions added in v0.8.0

func (c *View) TypeDefinitions() []*TypeDefinition

func (*View) UnwrapDatabaseType added in v0.2.2

func (v *View) UnwrapDatabaseType(ctx context.Context, value interface{}) (interface{}, error)

func (*View) ViewName added in v0.8.0

func (v *View) ViewName() string

func (*View) Warmup added in v0.8.0

func (v *View) Warmup() *Warmup

type Views

type Views []*View

Views wraps slice of NamedViews

func (Views) EnsureResource added in v0.8.0

func (v Views) EnsureResource(r *Resource)

func (Views) Index added in v0.8.0

func (v Views) Index() NamedViews

Index indexes Views by View.Name

func (Views) Init added in v0.8.0

func (v Views) Init(ctx context.Context, resource *Resource, transforms marshal.TransformIndex) error

Init initializes views.

type VisitorFn added in v0.8.0

type VisitorFn func(value interface{}) error

VisitorFn represents visitor function

type Warmup added in v0.2.11

type Warmup struct {
	IndexColumn string
	IndexMeta   bool       `json:",omitempty"`
	Connector   *Connector `json:",omitempty"`
	Cases       []*CacheParameters
}

Jump to

Keyboard shortcuts

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