import { getPool, closePool } from './connection.js'; import { ensureMigrationsTable, getAppliedMigrations, getMigrationFiles, applyMigration, parseMigrationFile } from './migration-runner.js'; import { introspectModels, introspectViews, getTopologicalOrder, schemasToSnapshot } from './schema-introspector.js'; import { loadLatestSnapshot, detectSchemaDrift } from './migration-generator.js'; import { buildInsert, buildUpdate, buildDelete, buildSelect, buildVectorSearch, buildHybridSearch } from './query-builder.js'; import { store } from '@stonyx/orm'; import { createRecord } from '../manage-record.js'; import { confirm } from '@stonyx/utils/prompt'; import { readFile } from '@stonyx/utils/file'; import { getPluralName } from '../plural-registry.js'; import config from 'stonyx/config'; import log from 'stonyx/log'; import path from 'path'; import type { Pool } from 'pg'; import type { OrmRecord } from '../types/orm-types.js'; interface PersistContext { record?: OrmRecord; recordId?: unknown; oldState?: Record; } interface PersistResponse { data?: { id: unknown; }; } interface SearchResult { record: OrmRecord; distance: number; } interface VectorSearchOptions { limit?: number; where?: Record; } interface PostgresDeps { getPool: typeof getPool; closePool: typeof closePool; ensureMigrationsTable: typeof ensureMigrationsTable; getAppliedMigrations: typeof getAppliedMigrations; getMigrationFiles: typeof getMigrationFiles; applyMigration: typeof applyMigration; parseMigrationFile: typeof parseMigrationFile; introspectModels: typeof introspectModels; introspectViews: typeof introspectViews; getTopologicalOrder: typeof getTopologicalOrder; schemasToSnapshot: typeof schemasToSnapshot; loadLatestSnapshot: typeof loadLatestSnapshot; detectSchemaDrift: typeof detectSchemaDrift; buildInsert: typeof buildInsert; buildUpdate: typeof buildUpdate; buildDelete: typeof buildDelete; buildSelect: typeof buildSelect; buildVectorSearch: typeof buildVectorSearch; buildHybridSearch: typeof buildHybridSearch; createRecord: typeof createRecord; store: typeof store; confirm: typeof confirm; readFile: typeof readFile; getPluralName: typeof getPluralName; config: typeof config; log: typeof log; path: typeof path; [key: string]: unknown; } export default class PostgresDB { /** PostgreSQL extensions to enable on pool init. Subclasses can override. */ static extensions: string[]; /** Config key under config.orm for this adapter. Subclasses can override. */ static configKey: string; /** Singleton instance, set by subclass constructor name. */ static instance: PostgresDB | undefined; deps: PostgresDeps; pool: Pool | null; pgConfig: Record; constructor(deps?: Partial); protected requirePool(): Pool; init(): Promise; startup(): Promise; shutdown(): Promise; save(): Promise; /** * Loads only models with memory: true into the in-memory store on startup. * Models with memory: false are skipped -- accessed on-demand via find()/findAll(). */ loadMemoryRecords(): Promise; /** * @deprecated Use loadMemoryRecords() instead. Kept for backward compatibility. */ loadAllRecords(): Promise; /** * Find a single record by ID from PostgreSQL. * Does NOT cache the result in the store for memory: false models. */ findRecord(modelName: string, id: string | number): Promise; /** * Find all records of a model from PostgreSQL, with optional conditions. */ findAll(modelName: string, conditions?: Record): Promise; /** * Perform a vector similarity search using cosine distance. */ vectorSearch(modelName: string, vectorColumn: string, queryVector: number[], options?: VectorSearchOptions): Promise; /** * Perform a hybrid search combining vector similarity with text filtering. */ hybridSearch(modelName: string, vectorColumn: string, queryVector: number[], textColumn: string, textQuery: string, options?: VectorSearchOptions): Promise; /** * Remove a record from the in-memory store if its model has memory: false. * The record object itself survives -- the caller retains the reference. * @private */ private _evictIfNotMemory; private _rowToRawData; persist(operation: string, modelName: string, context: PersistContext, response: PersistResponse): Promise; private _persistCreate; private _persistUpdate; private _persistDelete; private _recordToRow; } export {};