Spanish Total.js
Français
Documentation Pour les agents IA
Sommaire

Use databases in a flow

Read and write the rows of a database from a flow with its database component.

.md Site web

Cette page n’est pas encore traduite. Tu lis l’original.

Sur cette page

Every database of your app is also a component in the flow designer. You find them in the Databases group of the component list, with the name and icon of the database. When you create, change or remove a database, TAS updates these components in all flows.

What the component does

A database component has one input and two outputs:

  • Input: a message arrives and the component runs its code.
  • Output: the result of the code.
  • Error: the error, when the code fails.

The component shows the table it works with, for example db.db539792.

Write the code

Double-click the component in the designer to open its settings. The settings contain one piece of JavaScript. Select Read me to see the columns of the database.

The settings of the Customers component

The code returns the result of one of these methods:

  • READ() returns one row.
  • FIND() returns a list of rows.
  • LIST() returns a list of rows split into pages.
  • INSERT(data) inserts a row and returns its id.
  • UPDATE(data) updates rows.
  • REMOVE() removes rows.

Use each method on its own line. You can add conditions to it, for example .where('active', true). INSERT() and UPDATE() keep only the values of known columns and ignore the rest. INSERT() creates the id when the data has none.

data is the data of the incoming message. With a data view, data.query holds the query string of the request.

Some examples:

// all rows
return FIND();
// one row by the "id" in the query string
return READ().where('id', data.query.id);
// active customers only
return FIND().where('active', true);

After you change the code, select APPLY in the settings and then APPLY in the designer.

See Return database rows as JSON for a complete example.

Fabriqué en Europe