import { type SQL } from 'drizzle-orm'; import { MySqlDialect } from 'drizzle-orm/mysql-core'; import { type MySql2Database } from 'drizzle-orm/mysql2'; import { type PostgresJsDatabase } from 'drizzle-orm/postgres-js'; import { type Pool } from 'mysql2/promise'; import postgres from 'postgres'; export type DatabaseType = 'postgres' | 'mysql'; type PostgresDatabase = PostgresJsDatabase> & { $client: postgres.Sql; }; type MysqlDatabase = MySql2Database> & { $client: Pool; }; type PostgresDatabaseConnection = { databaseType: 'postgres'; client: postgres.Sql; db: PostgresDatabase; }; type MysqlDatabaseConnection = { databaseType: 'mysql'; client: Pool; dialect: MySqlDialect; db: MysqlDatabase; }; type DatabaseConnection = PostgresDatabaseConnection | MysqlDatabaseConnection; export type SqlExecutionResult = Record> = { databaseType: DatabaseType; rows: T[]; affectedRows?: number; insertId?: number | string | bigint; }; export type TransactionIsolationLevel = 'read committed' | 'repeatable read' | 'serializable'; export type TransactionOptions = { isolationLevel?: TransactionIsolationLevel; /** Number of retries after the first attempt for serialization/deadlock failures. */ retries?: number; }; export type TransactionSqlExecutor = = Record>(query: SQL) => Promise>; export type TransactionRunner = (callback: (executeSql: TransactionSqlExecutor) => Promise, options?: TransactionOptions) => Promise; export declare function normalizeTransactionRetries(value: number | undefined): number; export declare function detectDatabaseType(databaseUrl: string): DatabaseType; export declare function normalizeDatasourceName(datasource: unknown): string; export declare function datasourceDatabaseUrlEnvName(datasource: unknown): string; export declare function datasourceDatabaseUrl(datasource: unknown): { envName: string; databaseUrl: string; }; export declare function datasourceDatabaseType(datasource: unknown): DatabaseType; export declare function mokelayDatabaseUrl(): string; export declare function useDb(): PostgresDatabase; export declare function useDatasourceConnection(datasource: string): DatabaseConnection; /** * Closes and evicts a cached datasource connection, if one was opened. * This is primarily useful for finite-lived CLI commands and test runners. */ export declare function closeDatasourceConnection(datasource: string): Promise; export declare function useDatasourceDb(datasource: string): PostgresDatabase | MysqlDatabase; export declare function executeDatasourceSql = Record>(query: SQL, datasource: string): Promise>; /** * Runs all SQL through a single physical datasource connection. Callers should * still lock their own application-level serialization row inside the callback. */ export declare function executeDatasourceTransaction(datasource: string, callback: (executeSql: TransactionSqlExecutor) => Promise, options?: TransactionOptions): Promise; export {};