import type { ConnectionOptions } from 'node:tls'; import { MastraCompositeStore } from '@mastra/core/storage'; import type { StorageDomains } from '@mastra/core/storage'; import { Pool } from 'pg'; import type { PostgresStoreConfig } from '../shared/config.js'; import type { DbClient } from './client.js'; import { AgentsPG } from './domains/agents/index.js'; import { BackgroundTasksPG } from './domains/background-tasks/index.js'; import { BlobsPG } from './domains/blobs/index.js'; import { ChannelsPG } from './domains/channels/index.js'; import { DatasetsPG } from './domains/datasets/index.js'; import { ExperimentsPG } from './domains/experiments/index.js'; import { FavoritesPG } from './domains/favorites/index.js'; import { KnowledgePG } from './domains/knowledge/index.js'; import { MCPClientsPG } from './domains/mcp-clients/index.js'; import { MCPServersPG } from './domains/mcp-servers/index.js'; import { MemoryPG } from './domains/memory/index.js'; import { NotificationsPG } from './domains/notifications/index.js'; import { ObservabilityPG } from './domains/observability/index.js'; import { ObservabilityStoragePostgresVNext } from './domains/observability/v-next/index.js'; import type { VNextPostgresObservabilityConfig } from './domains/observability/v-next/index.js'; import { PromptBlocksPG } from './domains/prompt-blocks/index.js'; import { SchedulesPG } from './domains/schedules/index.js'; import { ScorerDefinitionsPG } from './domains/scorer-definitions/index.js'; import { ScoresPG } from './domains/scores/index.js'; import { SkillsPG } from './domains/skills/index.js'; import { ThreadStatePG } from './domains/thread-state/index.js'; import { ToolProviderConnectionsPG } from './domains/tool-provider-connections/index.js'; import { WorkflowDefinitionsPG } from './domains/workflow-definitions/index.js'; import { WorkflowsPG } from './domains/workflows/index.js'; import { WorkspacesPG } from './domains/workspaces/index.js'; /** * Exports the Mastra database schema as SQL DDL statements, including tables, indexes, and triggers. * Does not require a database connection. Each domain class provides its own DDL contribution * via a static getExportDDL method, ensuring a single source of truth. */ export declare function exportSchemas(schemaName?: string): string; export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, KnowledgePG, MCPClientsPG, MCPServersPG, MemoryPG, NotificationsPG, ObservabilityPG, ObservabilityStoragePostgresVNext, PromptBlocksPG, ScorerDefinitionsPG, ScoresPG, SchedulesPG, SkillsPG, FavoritesPG, ThreadStatePG, ToolProviderConnectionsPG, WorkflowsPG, WorkflowDefinitionsPG, WorkspacesPG, }; export type { VNextPostgresObservabilityConfig }; export { PoolAdapter } from './client.js'; export type { DbClient, TxClient, QueryValues, Pool, PoolClient, QueryResult } from './client.js'; export type { PgDomainConfig, PgDomainClientConfig, PgDomainPoolConfig, PgDomainRestConfig } from './db/index.js'; export { PgFactoryStorage, type PgFactoryStorageConfig } from './factory-storage.js'; /** * PostgreSQL storage adapter for Mastra. * * @example * ```typescript * // Option 1: Connection string * const store = new PostgresStore({ * id: 'my-store', * connectionString: 'postgresql://...', * }); * * // Option 2: Pre-configured pool * const pool = new Pool({ connectionString: 'postgresql://...' }); * const store = new PostgresStore({ id: 'my-store', pool }); * * // Access domain storage * const memory = await store.getStore('memory'); * await memory?.saveThread({ thread }); * * // Execute custom queries * const rows = await store.db.any('SELECT * FROM my_table'); * ``` */ export declare class PostgresStore extends MastraCompositeStore { #private; private schema; private isInitialized; stores: StorageDomains; constructor(config: PostgresStoreConfig); private createPool; init(): Promise; /** * Database client for executing queries. * * @example * ```typescript * const rows = await store.db.any('SELECT * FROM users WHERE active = $1', [true]); * const user = await store.db.one('SELECT * FROM users WHERE id = $1', [userId]); * ``` */ get db(): DbClient; /** Database client for queries that may run against the configured read replica. */ get readDb(): DbClient; /** The underlying writer pg.Pool for direct database access or ORM integration. */ get pool(): Pool; /** The underlying reader pg.Pool, falling back to the writer pool when unset. */ get readPool(): Pool; /** * Closes the writer connection pool if it was created by this store. * Caller-provided writer and reader pools are not closed. * Safe to call multiple times — subsequent calls are no-ops. */ close(): Promise; } /** * Required connection config for the v-next observability domain. Accepts * the same connection shapes as `PostgresStoreConfig` (pool / * connectionString / host+port / Cloud SQL connector) plus the * vNext-specific options. * * Required by design — `PostgresStoreVNext` will not implicitly share the * primary connection. Callers who want to share must pass identical * connection details here, and they'll receive a runtime warning every time * the store is constructed (and again on every init() over the same logger). */ export type PostgresStoreVNextObservabilityConfig = ({ pool: Pool; } | { connectionString: string; ssl?: ConnectionOptions | boolean; max?: number; idleTimeoutMillis?: number; } | { host: string; port?: number; database: string; user: string; password: string; ssl?: ConnectionOptions | boolean; max?: number; idleTimeoutMillis?: number; }) & { schemaName?: string; partitioning?: VNextPostgresObservabilityConfig['partitioning']; discovery?: VNextPostgresObservabilityConfig['discovery']; traceQueryTimeoutMs?: VNextPostgresObservabilityConfig['traceQueryTimeoutMs']; }; /** * Postgres storage adapter that uses the v-next observability domain. * * Composes a primary `PostgresStore` (memory / workflows / scores / agents / * etc.) with an `ObservabilityStoragePostgresVNext` for logs, metrics, * scores, feedback, and traces. * * The `observability` connection is **required**: every caller has to make * an explicit decision about where observability data goes. For production, * point it at a dedicated Postgres instance. For local development you can * pass the same connection details as the primary store — you'll get a * runtime warning every time the store is constructed. * * IMPORTANT: this adapter is intended for **low-volume production** * workloads only. For high-volume agent workloads, use the ClickHouse * adapter — Postgres (with or without TimescaleDB) cannot keep up past * roughly 1,500 calls/sec sustained on a single primary. * * @example * ```typescript * import { Mastra } from '@mastra/core'; * import { PostgresStoreVNext } from '@mastra/pg'; * * export const mastra = new Mastra({ * storage: new PostgresStoreVNext({ * id: 'app', * connectionString: process.env.DATABASE_URL!, * observability: { * connectionString: process.env.OBSERVABILITY_DATABASE_URL!, * }, * }), * }); * ``` */ export declare class PostgresStoreVNext extends PostgresStore { #private; constructor(config: PostgresStoreConfig & { /** * Connection config for the vNext observability domain. Required. * Pass a dedicated connection in production; reusing the primary * connection logs a runtime warning every construction. */ observability: PostgresStoreVNextObservabilityConfig; }); /** * Closes both the primary pool (when owned) and the observability pool * (when this store created it). Safe to call multiple times. */ close(): Promise; } //# sourceMappingURL=index.d.ts.map