A lightweight REST API for MySQL database access with stored procedure support.
Make arbitrary SQL calls against databases from within Postman test scripts. Manage test data, validate API results directly against the database and more.
NOTE: Currently only works for mySQL databases via the mysql2 driver package. If useful this could be expanded to use any sql driver.
This project provides a REST API that acts as a database agent, allowing you to:
- Execute SQL queries via HTTP endpoints
- Call MySQL stored procedures
- Access your database from Postman or any HTTP client
- Use your own database or the included sample database
- Setup initial test data
- Cleanup DBs after test runs
- Retrieve data for use in validating that requests/collection runs created the correct data in the DB
npm install# Copy the example configuration file
cp .env.example .env
# Edit .env with your database settings
# DB_HOST=localhost
# DB_USER=root
# DB_PASSWORD=your_password
# DB_NAME=users
# DB_PORT=3306Option A: Use your own database
- Configure your existing database in the
.envfile - Skip to step 4 to start the agent
Option B: Use the included sample database (Recommended for testing)
See the Sample DB README.md for details on the sample database setup.
node dbAgent.js- Import
postman/Postman_Database_Agent_Collection.jsoninto Postman - Start with the Status Check request
- Try the sample queries or use your own database queries
NOTE: The collection includes complete documentation for each request.
The agent will start on http://localhost:3000
- GET
/status- Check if the agent is running
- POST
/api/query- Execute custom SQL queries - POST
/api/procedure- Execute stored procedures
The colleciton contains additional documentation and examples.
curl -X POST http://localhost:3000/api/query \
-H "Content-Type: application/json" \
-d '{"query": "SELECT * FROM user LIMIT 5", "params": []}'curl -X POST http://localhost:3000/api/procedure \
-H "Content-Type: application/json" \
-d '{"procedure": "GetAllUsers", "params": []}'node-data/
├── dbAgent.js # Main database agent server
├── package.json # Dependencies
├── Postman_Database_Agent_Collection.json # Postman collection
├── postman/
│ └── postman-dbagent-package.js # Postman package module
├── db/ # Database files
│ ├── database_schema.sql # Complete database schema
│ ├── setup_database.sh # Complete setup script
│ ├── procedures/ # Stored procedures directory
│ │ ├── all_stored_procedures.sql # All procedures in one file
│ │ └── install_procedures.sh # Installation script
│ └── README.md # Database documentation
└── README.md # This file
The postman/postman-dbagent-package.js file is designed to be imported or copy-pasted into a Postman package for easy database operations within Postman scripts.
This package provides utility functions that wrap the database agent API, making it easy to execute SQL queries and stored procedures directly from Postman test scripts without writing raw HTTP requests.
sendSQL(querySql)- Execute custom SQL queriesexecProcedure(procName, params)- Execute stored procedures
// Execute a SQL query
const query = {
"query": "SELECT * FROM user LIMIT 5",
"params": []
};
const results = await sendSQL(query);
// Execute a stored procedure
const procResults = await execProcedure("GetAllUsers", []);The usage of this package is demonstrated in the Postman_Database_Agent_Collection.json collection, which includes:
- Raw script examples - Shows how to copy-paste the functions directly
- Package import examples - Shows how to use it as a Postman package
- Complete test scenarios - Demonstrates both SQL queries and stored procedure calls
- Simplified API calls - No need to write raw HTTP requests
- Error handling - Built-in error handling and response parsing
- Reusable - Can be used across multiple Postman collections