Supercheck LogoSupercheck
Automate

Database Test

Query and validate database stateEdit

Run SQL queries and validate database state directly. Database tests connect to your databases securely and execute queries with result validation.

Create Test

  1. Go to Create → Database Test
  2. Select database connection
  3. Write SQL query
  4. Add assertions
  5. Run and save

Example

/**
 * PostgreSQL read health check.
 * 
 * Purpose:
 * - Verify database connectivity
 * - Check that a specific table exists and has expected columns
 * - Ensure read operations are functioning
 * 
 * Configuration:
 * - Requires 'pg' library (included in Supercheck runtime)
 * - Connection string must be configured via project variables
 * 
 * @requires pg - PostgreSQL client for Node.js
 */
import { expect, test } from '@playwright/test';
import { Pool } from 'pg';

const pool = new Pool({
  host: getVariable('DB_HOST'),
  port: parseInt(getVariable('DB_PORT') || '5432'),
  database: getVariable('DB_NAME'),
  user: getVariable('DB_USER'),
  password: getSecret('DB_PASSWORD').toString(),
});

test.afterAll(async () => {
  await pool.end();
});

test.describe('database read health check', () => {
  test('users table returns expected columns', async () => {
    // Execute a simple SELECT query
    const result = await pool.query('SELECT id, email FROM users LIMIT 1');
    
    // Verify we got results and the schema matches expectations
    expect(result.rowCount).toBeGreaterThan(0);
    expect(result.rows[0]).toHaveProperty('email');
  });
});

Supported Databases

TypeDatabases
RelationalPostgreSQL, MySQL, SQL Server, MariaDB
CloudAmazon RDS, Azure SQL, Google Cloud SQL

Connection Methods

  • Direct — Public database with credentials
  • SSH Tunnel — Private network via bastion host
  • Secrets — Store credentials securely with getSecret().toString()

Common Assertions

AssertionExample
Row countCOUNT(*) > 0
Value checkstatus = 'active'
Not nullemail IS NOT NULL

Best Practices

  • Use read-only database users
  • Store credentials as secrets with getSecret().toString()
  • Set appropriate query timeouts
  • Use SSH tunnels for private databases
  • Always close connections in a finally block