package
0.9.0
Repository: https://github.com/viant/datly.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# 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:

SectionDescriptionTypeRequired
SourceURLstringfalse
MetricsView specific Metrics configuration inheritable by other Views MetricsMetricsfalse
ConnectorsDatabase connector definitions inheritable by other Views Connectors[]Connectorfalse
ViewsViews definitions provided by the resource[]Viewfalse
ParametersParameters configurations inheritable by other Views Parameters[]Parameterfalse
TypesInlined types definitions[]Typefalse
LoggersLoggers inheritable by other Views Loggers[]Loggerfalse

View

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

SectionDescriptionTypeRequiredDefault
RefOther View name that given View should inherit fromstringfalse
ConnectorConnector used by the ViewConnectortrue
NameUnique view namestring, unique across the Resourcetrue
AliasView table aliasstringfalse
TableTable name.stringTable, FromURL or From need to be specified
FromSQL inner select statement that will be used as source of datastringTable, FromURL or From need to be specified
FromURLSource of the SQL in case when SQL is specified in different filestringTable, FromURL or From need to be specified
ExcludeColumns that should not be exposed when column detection is performed[]stringfalse
ColumnsExplicitly specified columns that current View can use[]Columntrue
InheritSchemaColumnsIndicates whether all Columns that not match Struct Type should be removed or notboolfalsefalse
CaseFormatDatabase columns case formatCaseFormatfalselowerunderscore
CriteriaDynamic criteria expanded with the parameters valuesstringfalse
SelectorSelector configurationSelectorConfigfalse
TemplateTemplate configuration using parameters and velty syntaxTemplatefalse
SchemaView schema typeSchemafalse
WithView relations in order to produce results with nested objects[]Relationfalse
MatchStrategyMatch strategy specific for given ViewMatchStrategyfalseread_matched
BatchBatch configuration specific for given ViewBatchfalseBatch{Parent: 10000}
LoggerLogger specific for given ViewLoggerfalse
CounterMetrics specific for given ViewMetricsfalse

Column

SectionDescriptionTypeRequiredDefault
NameDatabase column namestringtrue
DataTypeColumn typeenum: Int, Float, Float64, Bool, String, Date, Timefalse
ExpressionSQL expression i.e. COALESCE(price, 0)stringfalse
FilterableIndicates whether column can be used using Selector criteria or notboolfalsefalse
NullableIndicates 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 expressionboolfalsefalse
DefaultDefault output value that will be replaced when zero value occurstringfalse
FormatDate output formatstringfalse

SelectorConfig

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

SectionDescriptionTypeRequiredDefault
OrderByDefault Column that will be used to Sortedstringfalse
LimitMaximum and default limit that can be used on the ViewintfalseNo default and maximum limit
ConstraintsSelector constraintsConstraintsfalseeverything 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.

SectionDescriptionTypeRequiredDefault
CriteriaAllows to parse _criteria into SQL statementbooleanfalsefalse
OrderByAllows to parse _orderBy into SQL order bybooleanfalsefalse
LimitAllows to parse _limit into SQL limitbooleanfalsefalse
OffsetAllows to parse _orrset into SQL offsetbooleanfalsefalse
FilterableAllowed columns to be used in the criteria, * in case of allowed all columns[]stringfalse

Parameter

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

SectionDescriptionTypeRequiredDefault
RefOther Parameter name that given Parameter will inherit fromstringfalse
NameIdentifier used to access parameter value in the templatesstringtrue
PresenceNameIdentifier used to check if parameter was set in the templatesstringfalsesame as Name
InSource of the parameterLocationtrue
RequiredIndicates if parameter is required or notbooleanfalsefalse
DescriptionParameter descriptionstringfalse
SchemaSchema configurationSchematrue
CodecCodec configurationCodecfalse

Location

SectionDescriptionTypeRequired
KindRepresents the source of the parameter i.e. Header, QueryParam.enum: query,header, cookie, data_view, body, envtrue
NameParameter source identifier i.e. Authorization, userIdstringtrue

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)
SectionDescriptionTypeRequired
NameCodec name, have to match the codec name provided programmaticallystringtrue

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.

SectionDescriptionTypeRequired
NameSchema name, needs to match one of the types provided programmaticallystringtrue unless DataType specified
DataTypePrimitive data type nameenum: Int, Float, Float64, Bool, String, Date, Timetrue 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.

SectionDescriptionTypeRequired
NameType namestringtrue
FieldsMetadata fields descriptions[]Fieldtrue

Field

SectionDescriptionTypeRequiredDefault
NameStruct field namestring, UpperCamelCasetrue
EmbedIndicates whether field should be Anonymous (i.e. while parsing JSON, if field is Anonymous and type of Struct the Struct will be flattened)boolfalsefalse
ColumnDatabase column namestringtrue unless name doesn't match actual database column name
SchemaField schemaSchemaSchema or Fields need to be specified
FieldsDescribes non-primitive field type[]FieldSchema 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.
SectionDescriptionTypeRequiredDefault
SourceThe actual SQL templatestringtrue
SourceURLIndicates whether field should be Anonymous (i.e. while parsing JSON, if field is Anonymous and type of Struct the Struct will be flattened)stringfalsefalse
SchemaThe actual type holder of the combined parameters. Each parameter name and type has to match the current Schema TypeSchemafalsefalse
PresenceSchemaSimilar to the Schema, but each Parameter name has to match field in the struct and every non primitive type has to be a booleanSchemafalsefalse
ParametersParameters that can be used inside the template[]Parameterfalsefalse

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.

SectionDescriptionTypeRequired
NameConnector namestringtrue
RefOther connector name which given connector should inherit fromstringfalse
DriverDatabase driverstringtrue
DSNDatabase source name, the uri needed to connect to database.stringtrue
SecretSecrettrue

Secret

Metrics

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

SectionDescriptionTypeRequired
URIPartstringtrue

Logger

Programmatically created and provided logger.

SectionDescriptionTypeRequired
RefOther Logger name which given Logger should inherit fromstringfalse
NameLogger namestringtrue

Batch

Batches data fetched from database.

SectionDescriptionTypeRequired
ParentNumber of parent placeholders in column in (?,?,?,?) statement if View is a child of any other Viewintfalse

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