Skip to main content

Datasets

Overview

The datasets module offers a suite of functions to interact with datasets through various web services. It allows users to fetch individual datasets, multiple datasets, and lists of dataset descriptions based on specific queries and parameters. This module is essential for applications that need to retrieve and manage data dynamically from different sources.

Key functionalities include:

  • Fetching a single dataset with fetchDataset.
  • Retrieving multiple datasets using fetchDatasets.
  • Obtaining a list of dataset descriptions via fetchDatasetList.

These functions ensure that users can efficiently access and handle datasets as per their requirements.

fetchDataset

Fetches a dataset from the specified web service and query name.

ParametersTypeDescription
webserviceNamestringThe name of the web service to fetch the dataset from.
queryNamestringThe name of the query to execute.
parametersobjectOptional parameters to pass to the query. Defaults to an empty object.
ReturnsDescription
Promise<T>A promise that resolves to the fetched dataset. Where T is the type of the dataset, defaults to Result.
ThrowsDescription
ErrorIf the dataset contains an error code and message.

Example Fetching a Single Dataset

import { fetchDataset } from 'datasets';

async function getSingleDataset() {
try {
const dataset = await fetchDataset('exampleService', 'exampleQuery', { param1: 'value1' });
console.log(dataset);
} catch (error) {
console.error('Error fetching dataset:', error);
}
}

getSingleDataset();

fetchDatasets

Fetches datasets from a specified web service.

Parameters

ParameterTypeDescription
webserviceNamestringThe name of the web service to fetch datasets from.
options{parameters?: {}, datasets?: string[]}The options for the request.
OptionsTypeDescription
parametersobjectOptional. The body of the request, defaults to an empty object.
datasetsstring[]Optional. An array of dataset names to fetch, defaults to an empty array.

Returns

  • Promise<DataSet<T>>: A promise that resolves to the fetched datasets.

Example Fetching Multiple Datasets

import { fetchDatasets } from 'datasets';

async function getMultipleDatasets() {
try {
const datasets = await fetchDatasets('exampleService', {
parameters: {value1: 'value1' },
datasets: ['dataset1', 'dataset2']
});
console.log(datasets);
} catch (error) {
console.error('Error fetching datasets:', error);
}
}

getMultipleDatasets();

fetchDatasetList

Fetches a list of dataset descriptions from the specified web service.

Parameters

ParameterTypeDescription
webserviceNamestringThe name of the web service to fetch the dataset list from.

Returns

  • Promise<DatasetDescription[]>: A promise that resolves to an array of DatasetDescription objects. This module provides functionality for retrieving and managing datasets based on user queries.

Example Fetching a List of Dataset Descriptions

import { fetchDatasetList } from 'datasets';

async function getDatasetList() {
try {
const datasetList = await fetchDatasetList('exampleService');
console.log(datasetList);
} catch (error) {
console.error('Error fetching dataset list:', error);
}
}

getDatasetList();