Skip to content

H2 API

The H2 API provides a set of operations for interacting with H2 databases, allowing users to connect, execute queries, create tables, insert records, fetch data, update tables, delete data, and manage database connections.

Why Integrate H2 Database with EasyTask?

Integrating H2 Database with EasyTask enables you to automate JDBC database operations for development and testing workflows. This integration allows you to:

  • Automate Database Operations: Execute SQL queries, create tables, insert records, and manage data programmatically as part of your EasyTask workflows.
  • Streamline Testing Pipelines: Leverage H2's lightweight in-memory database capabilities to automate setup and teardown of test databases through EasyTask orchestration.
  • Flexible Data Management: Fetch, update, and delete data with conditional queries, enabling sophisticated data processing and ETL workflows.

Required Values in Vault

{
"secret": {
    "class_path": "/path/to/the/jar/file.jar",
    "database_url": "jdbc:h2:~/<db-name>",
    "jdbc_driver_class": "org.h2.Driver",
    "password": "xxxx",
    "username": "xxxx"
}
}

Example Usage

curl -X POST http://localhost:8008/run-integration \
-H "Content-Type: application/json" \
-d '{
    "is_credentials": {
        "userid": "test",
        "passwd": "test123"
    },
    "integration": "h2",
    "uuid": "ae0e8ba9-423a-410e-bba5-e1933ff868c5",
    "init": {
        "vault_path_key": "h2/secret"
    },
    "action": [
        {
            "connect": {}
        }
    ]
}'
{
    "user": "h2_user",
    "integration": "h2",
    "uuid": "ae0e8ba9-423a-410e-bba5-e1933ff868c5",
    "init": {
        "vault_path_key": "h2/server1"
    },
    "error": false,
    "action": [
        {
            "connect": null
        }
    ]
}

Functions

connect

connect: This function establishes a connection to the H2 database.

This function takes no input parameters.

Output Parameter Type Description
response bool True if the connection was established successfully
{
    "connect": {}
}

execute

execute: This function executes a SQL query on the H2 database.

Input Parameter Type Description Mandatory
task str SQL query to execute yes
Output Parameter Type Description
response bool True if the query was executed successfully
{
    "execute": {
        "task": "DROP TABLE TEST IF EXISTS"
    }
}

create_table

create_table: This function creates a new table in the H2 database.

Input Parameter Type Description Mandatory
table_name str Name of the table to create yes
cols list List of column definitions yes
Output Parameter Type Description
response bool True if the table was created successfully
{
    "create_table": {
        "table_name": "TEST",
        "cols": [
            "id int",
            "name varchar(100)"
        ]
    }
}

insert_record

insert_record: This function inserts records into a table in the H2 database.

Input Parameter Type Description Mandatory
table_name str Name of the table to insert into yes
records list List of records to insert yes
Output Parameter Type Description
response bool True if the records were inserted successfully
{
    "insert_record": {
        "table_name": "TEST",
        "records": [
            [1, "test_name"]
        ]
    }
}

fetch_all

fetch_all: This function retrieves all records from a table in the H2 database.

Input Parameter Type Description Mandatory
table_name str Name of the table to fetch from yes
Output Parameter Type Description
response list List of all records in the table
{
    "fetch_all": {
        "table_name": "TEST"
    }
}

fetch_data

fetch_data: This function retrieves records from a table in the H2 database based on specified conditions.

Input Parameter Type Description Mandatory
table_name str Name of the table to fetch from yes
where list List of conditions for the WHERE clause yes
Output Parameter Type Description
response list List of records matching the conditions
{
    "fetch_data": {
        "table_name": "TEST",
        "where": ["id > 0"]
    }
}

update_table

update_table: This function updates records in a table in the H2 database.

Input Parameter Type Description Mandatory
table_name str Name of the table to update yes
upd list List of update statements yes
where list List of conditions for the WHERE clause yes
Output Parameter Type Description
response bool True if the update was successful
{
    "update_table": {
        "table_name": "TEST",
        "upd": ["id=2", "name='new_test'"],
        "where": ["id=1"]
    }
}

delete_data

delete_data: This function deletes records from a table in the H2 database.

Input Parameter Type Description Mandatory
table_name str Name of the table to delete from yes
where list List of conditions for the WHERE clause yes
Output Parameter Type Description
response bool True if the deletion was successful
{
    "delete_data": {
        "table_name": "TEST",
        "where": ["id=2"]
    }
}

drop_table

drop_table: This function drops (deletes) a table from the H2 database.

Input Parameter Type Description Mandatory
table_name str Name of the table to drop yes
Output Parameter Type Description
response bool True if the table was dropped successfully
{
    "drop_table": {
        "table_name": "TEST"
    }
}

disconnect

disconnect: This function closes the connection to the H2 database.

This function takes no input parameters.

Output Parameter Type Description
response bool True if the connection was closed successfully
{
    "disconnect": {}
}

Frequently Asked Questions

How do I configure H2 Database credentials in EasyTask?

Use the EasyTask vault system to securely store your H2 Database connection credentials. Navigate to the integration configuration page and add your JDBC URL, driver class, JAR path, username, and password under a vault key like h2/secret.

Can I use H2 Database with both EasyTask Cloud and On-Premises?

Yes, H2 Database works seamlessly with both EasyTask Cloud and On-Premises deployments. The configuration process is identical.

How do I troubleshoot H2 Database connection issues?

Check the integration server logs in EasyTask for detailed error messages. Verify your JDBC URL, driver class path, and credentials in the vault, ensure the H2 JAR file is accessible, and test connectivity using the built-in connection test feature.

Next Steps