# Database Schema Explorer (`balathon/database-schema-explorer`) Actor

This Apify Actor connects to various types of databases (SQLite, PostgreSQL, MySQL, Oracle, Microsoft SQL Server), explores their schemas, provides detailed information about tables and columns, shows row counts, and optionally reads sample data.

- **URL**: https://apify.com/balathon/database-schema-explorer.md
- **Developed by:** [Balasai Sigireddy](https://apify.com/balathon) (community)
- **Categories:** Developer tools, Other
- **Stats:** 1 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.01 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Database Schema Explorer

[![Apify Actor](https://img.shields.io/badge/Apify-Actor-green)](https://console.apify.com/actors/OFPqTSGvR8YnLhU5h)
[![Version](https://img.shields.io/badge/Version-0.0.3-blue)](https://console.apify.com/actors/OFPqTSGvR8YnLhU5h)

This Apify Actor connects to various types of databases (SQLite, PostgreSQL, MySQL, Oracle, Microsoft SQL Server), explores their schemas, provides detailed information about tables and columns, shows row counts, optionally reads sample data, and can generate visual schema diagrams.

### Supported Databases

| Database Type | Connection Method | Status |
|---------------|------------------|---------|
| **SQLite** | File upload or connection string | ✅ Fully Supported |
| **PostgreSQL** | Connection string | ✅ Fully Supported |
| **MySQL** | Connection string | ✅ Fully Supported |
| **SQL Server** | Connection string | ✅ Fully Supported |
| **Oracle** | Connection string | ⚠️ Requires Oracle client |

#### Database Connection Examples

- **SQLite**: `sqlite:///path/to/database.db` or upload `.db` file
- **PostgreSQL**: `postgresql://user:password@host:port/database`
- **MySQL**: `mysql://user:password@host:port/database`
- **SQL Server**: `mssql://user:password@host:port/database`

### Input Parameters

- `db_type`: Database type (sqlite, postgresql, mysql, oracle, mssql)
- `connection_string`: Database connection string (e.g., 'sqlite:///database.db' or 'postgresql://user:pass@host:port/db'). For SQLite, you can alternatively upload a database file.
- `sqlite_file`: Upload a SQLite database file (.db) to explore (only for SQLite databases)
- `tables_to_explore`: List of specific table names to explore (optional, explores all if empty)
- `include_sample_data`: Whether to include sample data (default: true)
- `max_sample_rows`: Maximum number of sample rows per table (default: 10)
- `generate_schema_image`: Whether to generate a visual diagram of the database schema (default: false)
- `diagram_type`: Type of diagram to generate (mermaid, plantuml, graphviz) - required if generate\_schema\_image is true
- `output_format`: Output format for the diagram (png, svg, pdf) - required if generate\_schema\_image is true

### Output

The Actor outputs structured JSON data to a dataset, containing for each table:

- Table name
- Row count
- Column details (name, type, nullable, default)
- Sample data (if requested)

If schema image generation is enabled, a visual diagram is also stored in the key-value store.

#### Example Output Structure

```json
{
  "table_name": "users",
  "row_count": 5,
  "columns": [
    {
      "name": "id",
      "type": "INTEGER",
      "nullable": false,
      "default": null
    },
    {
      "name": "name",
      "type": "TEXT",
      "nullable": false,
      "default": null
    }
  ],
  "sample_data": [
    {
      "id": 1,
      "name": "Alice Johnson",
      "email": "alice@example.com"
    }
  ]
}
```

#### Schema Visualization

When `generate_schema_image` is enabled, the Actor generates a visual diagram of your database schema using one of three supported diagram types:

##### Diagram Types

- **Mermaid**: Clean, modern ER diagrams using Mermaid.js
- **PlantUML**: Traditional UML entity-relationship diagrams
- **Graphviz**: Record-based table representations using DOT language

##### Output Formats

- **PNG**: Raster image format (default)
- **SVG**: Scalable vector graphics
- **PDF**: Portable document format

The generated diagram includes all explored tables with their column names, data types, and nullability constraints. The image is stored in the Actor's key-value store and can be accessed via the output schema template.

### Quick Start

🚀 **Try it now**: [Run on Apify](https://console.apify.com/actors/OFPqTSGvR8YnLhU5h)

#### For SQLite Testing

1. Download the included `dummy.db` file from this repository
2. Go to the [Actor page](https://console.apify.com/actors/OFPqTSGvR8YnLhU5h)
3. Upload the `dummy.db` file as the SQLite file parameter
4. Run the actor and explore the results!

#### For Other Databases

1. Set your database connection parameters
2. Choose the appropriate database type
3. Run the actor to explore your database schema

#### Testing with Dummy Database

A sample SQLite database (`dummy.db`) is included in the repository for testing purposes. It contains:

- **users** table: 5 users with id, name, email, age, created\_at
- **products** table: 5 products with id, name, price, category, stock
- **orders** table: 20 sample orders linking users and products

You can upload this file when testing the Actor with SQLite database type.

### Local Development

To run the Actor locally:

```bash
apify run
```

### Deploy to Apify

✅ **Already Deployed!** This actor is live at: https://console.apify.com/actors/OFPqTSGvR8YnLhU5h

#### Connect Git repository to Apify

If you've created a Git repository for the project, you can easily connect to Apify:

1. Go to [Actor creation page](https://console.apify.com/actors/new)
2. Click on **Link Git Repository** button

#### Push project on your local machine to Apify

You can also deploy the project on your local machine to Apify without the need for the Git repository.

1. Log in to Apify. You will need to provide your [Apify API Token](https://console.apify.com/account/integrations) to complete this action.

   ```bash
   apify login
   ```

2. Deploy your Actor. This command will deploy and build the Actor on the Apify Platform. You can find your newly created Actor under [Actors -> My Actors](https://console.apify.com/actors?tab=my).

   ```bash
   apify push
   ```

### Documentation reference

To learn more about Apify and Actors, take a look at the following resources:

- [Apify SDK for JavaScript documentation](https://docs.apify.com/sdk/js)
- [Apify SDK for Python documentation](https://docs.apify.com/sdk/python)
- [Apify Platform documentation](https://docs.apify.com/platform)
- [Join our developer community on Discord](https://discord.com/invite/jyEM2PRvMU)

# Actor input Schema

## `db_type` (type: `string`):

Type of database to connect to

## `connection_string` (type: `string`):

Database connection string (e.g., 'sqlite:///database.db' or 'postgresql://user:pass@host:port/db'). For SQLite, you can alternatively upload a database file.

## `sqlite_file` (type: `string`):

Upload a SQLite database file (.db) to explore. Only used when db\_type is 'sqlite'.

## `tables_to_explore` (type: `array`):

List of table names to explore. If empty, all tables will be explored.

## `include_sample_data` (type: `boolean`):

Whether to include sample rows from each table

## `max_sample_rows` (type: `integer`):

Maximum number of sample rows to read per table

## `generate_schema_image` (type: `boolean`):

Whether to generate an image representation of the database schema

## `diagram_type` (type: `string`):

Type of diagram to generate for the schema image

## `output_format` (type: `string`):

Format of the generated schema image

## Actor input object example

```json
{
  "db_type": "sqlite",
  "connection_string": "sqlite:///example.db",
  "tables_to_explore": [],
  "include_sample_data": true,
  "max_sample_rows": 10,
  "generate_schema_image": false,
  "diagram_type": "mermaid",
  "output_format": "png"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("balathon/database-schema-explorer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("balathon/database-schema-explorer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call balathon/database-schema-explorer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,balathon/database-schema-explorer"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/OFPqTSGvR8YnLhU5h/builds/5yg3gCJmivTSTw14H/openapi.json
