Documentation Index
Fetch the complete documentation index at: https://mintlify.com/manusapis/Agix/llms.txt
Use this file to discover all available pages before exploring further.
The SQL connector lets Agix treat your database as a first-class data source. Supply a connection string and credentials, pass a SQL query or a table name as the resource, and the result-set lands in the active sheet as a clean row-by-column table. Combined with the Agix scheduler, you can automate daily or hourly refreshes so the AI always works from current data without any manual export step.
SQLConnector class
SQLConnector extends BaseConnector with type set to "sql". Beyond the standard connect, disconnect, and sync methods, it exposes two additional methods for direct programmatic use:
import { BaseConnector } from "./base.connector";
import type { ConnectorConfig, SyncRequest, SyncResult } from "@/types/connector.types";
export class SQLConnector extends BaseConnector {
constructor() {
super("sql");
}
async connect(config: ConnectorConfig): Promise<boolean> {
this.config = config;
return true;
}
async disconnect(): Promise<void> {
this.config = null;
}
async sync(request: SyncRequest): Promise<SyncResult> {
return {
connector: "sql",
resource: request.resource,
syncedAt: new Date().toISOString(),
rowsInserted: 0,
rowsUpdated: 0,
};
}
async query(sql: string): Promise<Record<string, unknown>[]> { ... }
async listTables(): Promise<string[]> { ... }
}
Methods
| Method | Signature | Description |
|---|
connect | (config: ConnectorConfig) => Promise<boolean> | Stores credentials and validates the connection |
disconnect | () => Promise<void> | Clears stored credentials |
sync | (request: SyncRequest) => Promise<SyncResult> | Executes request.resource as a query or table name and writes rows to the sheet |
query | (sql: string) => Promise<Record<string, unknown>[]> | Runs an arbitrary SQL string and returns rows directly |
listTables | () => Promise<string[]> | Returns the list of table names accessible with the current credentials |
Connecting to a database
Pass database credentials through the ConnectorConfig.credentials map. The keys Agix expects match standard connection parameters:
import { createConnector } from "@/services/connectors/connector.factory";
import type { ConnectorConfig } from "@/types/connector.types";
const config: ConnectorConfig = {
type: "sql",
name: "Analytics DB",
credentials: {
host: "db.example.com",
port: "5432",
database: "analytics",
username: "readonly",
password: "...",
},
enabled: true,
};
const connector = createConnector("sql");
const connected = await connector.connect(config);
All values in credentials are strings — cast numeric values like port accordingly.
Syncing data with sync()
SyncRequest.resource accepts either a plain table name or a full SQL query string. Agix writes the returned rows into the active sheet:
import type { SyncRequest } from "@/types/connector.types";
// Sync an entire table
const tableSync: SyncRequest = {
connector: "sql",
resource: "monthly_revenue",
};
// Sync the result of a custom query
const querySync: SyncRequest = {
connector: "sql",
resource: "SELECT region, SUM(amount) AS total FROM orders WHERE created_at >= '2024-01-01' GROUP BY region",
};
const result = await connector.sync(querySync);
console.log(`Inserted ${result.rowsInserted} rows, updated ${result.rowsUpdated}`);
SyncResult returns a syncedAt ISO timestamp alongside the row counts so you can confirm freshness at a glance.
Running direct queries with query()
For ad-hoc exploration or custom automation scripts, call query() directly instead of going through sync():
const connector = createConnector("sql") as SQLConnector;
await connector.connect(config);
const rows = await connector.query(
"SELECT customer_id, plan, status FROM subscriptions WHERE status = 'past_due'"
);
// rows is Record<string, unknown>[] — each element is one result row
Discovering available tables
Before writing a query, use listTables() to inspect what is accessible with the current credentials:
const tables = await connector.listTables();
// e.g. ["orders", "customers", "monthly_revenue", "events"]
This is especially useful when connecting to a shared database where schema knowledge is incomplete.
Always connect Agix with a read-only database user. Never supply credentials for an account that has INSERT, UPDATE, DELETE, or DROP permissions. Agix reads data — it has no need for write access — and restricting the database user to SELECT prevents accidental or malicious data modification. Create a dedicated agix_readonly role in your database and grant it access only to the schemas Agix needs.
Pair the SQL connector with the Agix scheduler for fully automated data refreshes. Schedule a sync task to run every morning before business hours, and your spreadsheet will always contain up-to-date query results when you open it. You can then configure a follow-up AI task in the same schedule to re-run your analysis automatically — no manual steps required.