import { getPool, closePool } from './connection.js'; import type { MysqlConfig } 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 } from './query-builder.js'; 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 path from 'path'; import type { Pool } from 'mysql2/promise'; import type { OrmRecord } from '../types/orm-types.js'; interface PersistContext { record?: OrmRecord; recordId?: unknown; oldState?: Record; } interface PersistResponse { data?: { id?: unknown; }; } interface OrmStore { get(key: string): Map | undefined; get(key: string, id: number | string): unknown; _memoryResolver?: (modelName: string) => boolean; data?: Map>; } interface MysqlDBDeps { 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; createRecord: typeof createRecord; store: OrmStore; confirm: typeof confirm; readFile: typeof readFile; getPluralName: typeof getPluralName; config: typeof config; log: Record void) | undefined>; path: typeof path; } export default class MysqlDB { static instance: MysqlDB | undefined; deps: MysqlDBDeps; pool: Pool | null; mysqlConfig: MysqlConfig; constructor(deps?: Partial); private requirePool; 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 MySQL. * 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 MySQL, with optional conditions. */ findAll(modelName: string, conditions?: Record): 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. * This prevents on-demand queries from leaking records into the store. */ private _evictIfNotMemory; private _rowToRawData; persist(operation: string, modelName: string, context: PersistContext, response: PersistResponse): Promise; private _persistCreate; private _persistUpdate; private _persistDelete; private _recordToRow; } export {};