Database Call
  • 20 Nov 2023
  • 3 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Database Call

  • Dark
    Light
  • PDF

Article Summary

Overview

The Database Call node lets you write and execute SQL queries directly within Corezoid, removing the need for writing custom APIs to access databases. With the Database Call node, managing and accessing data in your databases becomes straightforward and streamlined.
Supported databases:

  • MySQL
  • Microsoft SQL Server
  • PostgreSQL
  • Oracle
  • MongoDB

To use the Database Call node, first, you need to connect your database to Corezoid.

Database Call flow

Settings

The Database Call node has the following parameters:

  1. (Optional) Title and Description: Name and details of the node.

  2. Basic settings:
    Connection: Shows the database connection
    Note: For more information about how to connect your database to Corezoid, go to Examples.

  3. SQL Query: Indicates your SQL query.
    Note: To access task parameters, use curly braces: {{some_parameter}}. Ensure that the query result does not surpass the maximum task size limit.

  4. Code editor: Shows the JSON format of the entered key and value. You can write and include additional code, which will be executed when a task enters the node.

  5. Other:

    • Alert if the number of tasks in the node queue reaches the following number: Helps monitor whether the number of tasks in the node exceeds the specified threshold. When selecting the checkbox, you have to enter the needed number of tasks in the field that appears below.
    • Maximum interval, for which the task stays in the node before being forwarded: The amount of time a task is allowed to be in the node; can be set in seconds, minutes, hours, and days.
      Note: The checkbox has a minimum value of 30 seconds. You can set a shorter interval by using the Unixtime function.

    Database Call settings

Examples

  • Create a table

    CREATE TABLE alc (
        user_id integer,
        conveyor_id integer,
        name text,
        description text
    );
    
  • Insert a new row into a table

    INSERT INTO alc (user_id, conveyor_id, name, description)
    VALUES (13, 777000, 'Send Message', 'Use to send text messages to phone number')
    
  • Call stored function with one parameter (PostgreSQL)

    SELECT function_name(arg)
    
  • Select data from two tables using JOIN

    SELECT alb.conveyor_id, CONCAT('https:://api.corezoid.com/api/2/json/', alb.hash) as URL, alc.* 
    FROM "public"."alb" alb
    LEFT JOIN "public"."alc" alc ON alc.conveyor_id = alb.conveyor_id
    WHERE alc.conveyor_id is not null
    
  • Update data based on task parameters
    Change the value of the hash field with the value of {{URL}} parameter for a row with conveyor_id equals to {{conv_id}}.

    UPDATE alb
    SET hash = '{{URL}}'
    WHERE conveyor_id = '{{conv_id}}'
    

Error handling & troubleshooting

When an error occurs during the task processing, you may see the following error parameter names in the task.

Error parameter nameParameter description
__conveyor_db_call_return_type_error__Hardware (system error), Software (error in a node logic/settings).
__conveyor_db_call_return_type_tag__*Error tag.
__conveyor_db_call_return_type_description__Error description in human-readable language; can be static or dynamic.

*The error tag __conveyor_db_call_return_type_tag__ may have the following values.

ValueCauseSolution
access_deniedYou don't have permission to send a reply to the indicated Process.Contact the Process owner for further assistance.
access_deniedYou are trying to connect to the database from another stage.It's not allowed to connect to databases from other stages. Use the same stage to connect to the needed database.
db_call_return_format_errorIncorrect format of the response from the Database Call node.Contact the support team for further assistance.
db_call_executing_errorThe Database Call node returned an incorrect code.Contact the support team for further assistance.
not_found_conv_by_aliasYour alias refers to a Process that no longer exists.Use an existing Process.
db_call_fatal_errorA hardware error has occurred.Contact the support team for further assistance.

When working with your Process, you may encounter the following issues.

IssueCauseSolution
Connection to the database is lost.The database you are trying to connect to is down.This issue is caused by a database failure and is not related to the Corezoid platform.
Can't reach the component that connects to the database.The on-premise connection has been lost because the database is not functioning.Check your database connection and credentials.

Was this article helpful?

What's Next