/** * Natural Language Postgres * * Provides NL->SQL capabilities for querying PostgreSQL databases. */ export interface PostgresConfig { /** Database connection URL */ connectionUrl: string; /** Schema to use (default: public) */ schema?: string; /** Read-only mode (default: true for safety) */ readOnly?: boolean; /** Allowed tables (whitelist) */ allowedTables?: string[]; /** Blocked tables (blacklist) */ blockedTables?: string[]; /** Maximum rows to return (default: 100) */ maxRows?: number; /** Query timeout in ms (default: 30000) */ timeout?: number; } export interface TableSchema { name: string; columns: ColumnSchema[]; primaryKey?: string[]; foreignKeys?: ForeignKey[]; } export interface ColumnSchema { name: string; type: string; nullable: boolean; defaultValue?: string; description?: string; } export interface ForeignKey { columns: string[]; referencedTable: string; referencedColumns: string[]; } export interface QueryResult { rows: any[]; rowCount: number; fields: { name: string; type: string; }[]; executionTime: number; } export interface NLQueryResult { /** Natural language query */ query: string; /** Generated SQL */ sql: string; /** Query result */ result: QueryResult; /** Explanation of the query */ explanation?: string; } /** * Create a Natural Language Postgres client. * * @example Basic usage * ```typescript * import { createNLPostgres } from 'praisonai/integrations/postgres'; * * const db = await createNLPostgres({ * connectionUrl: process.env.DATABASE_URL!, * readOnly: true * }); * * // Query with natural language * const result = await db.query('Show me all users who signed up last month'); * console.log(result.rows); * ``` * * @example With schema introspection * ```typescript * const db = await createNLPostgres({ connectionUrl: '...' }); * * // Get schema information * const schema = await db.getSchema(); * console.log('Tables:', schema.map(t => t.name)); * * // Query with context * const result = await db.query('How many orders were placed today?'); * ``` */ export declare function createNLPostgres(config: PostgresConfig): Promise; export declare class NLPostgresClient { private config; private pool; private schema; private connected; constructor(config: PostgresConfig); /** * Connect to the database. */ connect(): Promise; /** * Disconnect from the database. */ disconnect(): Promise; /** * Load database schema. */ private loadSchema; /** * Get the database schema. */ getSchema(): TableSchema[]; /** * Get schema as a string for LLM context. */ getSchemaContext(): string; /** * Execute a raw SQL query. */ executeSQL(sql: string): Promise; /** * Query the database using natural language. */ query(naturalLanguageQuery: string, options?: { model?: string; }): Promise; /** * Chat with the database (conversational interface). */ chat(message: string, options?: { model?: string; history?: Array<{ role: string; content: string; }>; }): Promise; /** * Inspect the database structure. */ inspect(): Promise<{ tables: number; schema: TableSchema[]; sampleData: Record; }>; } /** * Create a tool for querying Postgres with natural language. * * @example Use with an agent * ```typescript * import { Agent } from 'praisonai'; * import { createPostgresTool } from 'praisonai/integrations/postgres'; * * const dbTool = await createPostgresTool({ * connectionUrl: process.env.DATABASE_URL! * }); * * const agent = new Agent({ * instructions: 'You can query the database', * tools: [dbTool] * }); * ``` */ export declare function createPostgresTool(config: PostgresConfig): Promise;