- Getting Started
- Administration Guide
-
User Guide
- An Introduction to Wyn Enterprise
- Document Portal for End Users
-
Data Governance and Modeling
- Data Binding Concepts
-
Introduction to Data Sources
- Connect to Oracle
- Connect to SQL Server
- Connect to MySQL
- Connect to Postgres
- Connect to Snowflake
- Connect to SQLite
- Connect to DM
- Connect to TiDB
- Connect to AnalyticDB(MySQL)
- Connect to GreenPlum
- Connect to TimeScale
- Connect to Amazon Redshift
- Connect to MariaDB
- Connect to ClickHouseV2
- Connect to MonetDB
- Connect to Kingbase
- Connect to GBase8a
- Connect to GBase8s
- Connect to ClickHouse
- Connect to IBM DB2
- Connect to IBM DB2 iSeries/AS400
- Connect to Doris
- Connect to Kylin
- Connect to StarRocks
- Connect to Google BigQuery
- Connect to Hive (beta)
- Connect to ElasticSearch (beta)
- Connect to Hana
- Connect to Excel
- Connect to JSON
- Connect to CSV
- Connect to XML
- Connect to MongoDB
- Connect to ElasticSearchDSL
- Connect to InfluxDB
- Connect to SSAS
- Connect to ODBC
- Connect to OData
- Connect to TDengine
- Connect to Teradata
- Connect to a Custom Data Provider
- Introduction to Data Model
- Introduction to Direct Query Model
- Introduction to Cached Model
- Introduction to Datasets
- How To
- Secure Data Management
- Working with Resources
- Working with Reports
- Working with Dashboards
- View and Manage Documents
- Understanding Wyn Analytical Expressions
- Section 508 Compliance
- Subscribe to RSS Feed for Wyn Builds Site
- Developer Guide
Connect to a Javascript Data Provider
Connect Using a Javascript Custom Connector
If you have a Javascript custom data source, click the icon to create a Wyn data source.
Connection String
Give your data source a suitable name from the API you are using as a data source.
The connection string for the data source is a list of properties for the Javascript engine that will be used to interpret your Javascript queries later. It consists of four properties but the engine property has to be Jint as it is the only supported Javascript engine for now.
Engine (Required): Currently, the Javascript custom provider only supports the Jint script engine.
LimitMemory (Optional): Limits the memory allocation to a given amount in MB. The default is 100MB.
TimeoutInterval (Optional): The timeout interval in seconds. The default is 30 seconds.
MaxStatements (Optional): The maximum number of script statements that can be executed. The default is 2000.
Here's an example connection string and a screenshot:
Engine = Jint;
LimitMemory = 100;
TimeoutInterval = 30;
MaxStatements = 2000;
In the example in the screenshot below, we use Typicode to fetch random blog post data. So we called the data source "Typicode Posts Data Source"
Test the connection.
Create a Native Query Dataset
The next step after creating a data source is to create a dataset. In the Resource Portal, navigate to Create (+) > Create Data Source and choose Prepare Data under DASHBOARD or REPORT and choose Native Query Dataset
Choose the Data Source you created earlier from the pulldown and write the text of a Javascript snippet in the Query textbox.
Here we use a snippet that fetches the blog posts from the API and adds them to a predefined variable called resultset. The variables and functions that could be used in the query text are explained below.
resultset.schema({
userId: 'integer',
id: 'integer',
title: 'string',
body: 'string'
});
var response = helper.fetch(
'https://jsonplaceholder.typicode.com/posts');
JSON.parse(response.body).forEach(
r => resultset.row(r));
Press Validate to make sure your query does not have syntax errors. If it works, preview the results by pressing the Preview button and then Save the query and give it a name.
Command text pattern
The command text is a Javascript code snippet that should be written in pure Javascript as browser APIs (Functions like fetch()) are not available. The Wyn custom Javascript provider, however, has predefined objects to help you construct the result set:
resultset: where you define the schema object property.
helper object that has a function (fetch)
variable: resultset
Sample code setting resultset schema:
resultset.schema({
column1: 'string',
column2: 'integer'
});
The available data types are string
, integer
, double
, decimal
, boolean,
and datetime
. Invalid data types will be treated asstring
.
Sample code adding a single row to resultset:
resultset.row(['value1', 123]);
or
resultset.row({column1:'value1', column2:123});
If the parameter is an array, the order of the values should match the order of the columns in the schema.
The array length can be less or greater than the column count, in which case the mismatched columns will be filled with null values.
If the parameter is an object, the keys should match the column names in the schema. The object can contain more or fewer keys than the column count, in which case the mismatched columns will be filled with null values.
variable: helper
As the most common use case is to fetch data via RESTful API, this provider injects a helper object that has a fetch function.
Sample code fetching data from RESTful API:
var response =
helper.fetch('https://jsonplaceholder.typicode.com/posts');
or
var response =
helper.fetch(
'https://jsonplaceholder.typicode.com/posts', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
This fetch() function is different from the popular browser fetch() function. It does not return a promise. Instead, it returns a response object.
You can access the following properties of the response object:
status: Integer. The HTTP status code.
statusText: String. The HTTP status text.
headers: Object. The response headers.
body: String. The literal raw response body.
Data type conversion
The types defined in the schema are used to convert the values in the row.
If the value cannot be converted to the specified type, an exception will be thrown.