Skip to main content

Data Sources

Overview

Data sources play a central role in the Godspeed Framework, serving as the origins or locations from which data can be collected and stored. This documentation provides an overview of data sources within the framework, their usage, and how to invoke them from within workflow tasks.

In the Godspeed Framework, data sources are fundamental components that enable users to access and manipulate data from various origins. Examples of data sources include databases,message bus, cache, file systems, and third-party APIs.

Data sources can be seamlessly integrated into your workflow tasks using a standardized syntax. The key element for invoking data sources is the fn attribute, which is namespaced under datasource. Here's an example of how data sources are used within a workflow task:

Demonstration

Datasource Types

Datasources can be divided into two types, "Datastore as datasource" and "API as a datasource"

event types

Example 1: Datastore as Datasource prisma-as-datastore

import { GSContext, GSStatus } from "@godspeedsystems/core";

module.exports = async (ctx: GSContext) => {
const { inputs: { data: { params } }, logger, datasources } = ctx;

const response = await datasources.mongo.client.Post.findUnique({
where: { id: params.id }
});
return new GSStatus(true, 200, "Post fetched", response );
}

In this example:

datasources.mongo.client.Post.findUnique is the datasource function, which can be described as below:

  • datasources: fixed namespace for all data sources for typescript functions
  • mongo: name of datasource (name of prisma schema in case of prisma datasource), you can use any database provider, checkout supported databases list
  • Post: entity name
  • findUnique: method to be invoked in entity name

the workflow is consuming the datasource mongo and finding one document from Post entity.

Godspeed has "Prisma as datastore plugin", which provides a uniform access to all databases

To enable this seamless interaction with datasources, the Godspeed Framework allows you to configure data sources within your project. For instance, the example mentions the use of the "prisma-as-datastore" plugin to define the "mongo" data source. This configuration step ensures that the framework can establish connections and communicate effectively with the specified data source.

In the above example there is a mongo datasource defined in the project, you are free to name your datasource as you like. A default config of your datasource is present in src/datasources folder.

Example 2: API Datasource axios-as-datasource

import { GSContext, GSDataSource, logger, PlainObject } from "@godspeedsystems/core";

export default async function (ctx: GSContext) {
const res = await ctx.datasources.api.execute(ctx, {
meta: {
method: 'get',
url: '/anything',
},
});
return res;
};

In the above example:

  • datasources: fixed namespace for all data sources
  • api: name of data source,
  • get: API method
  • ./anything: API endpoint