@msugiura/rawsql-prisma
Version:
Prisma integration for rawsql-ts - Dynamic SQL generation with type safety and hierarchical JSON serialization
144 lines (143 loc) • 4.28 kB
TypeScript
import { TableColumnResolver } from 'rawsql-ts';
import { PrismaClientType, PrismaModelInfo, RawSqlClientOptions, PrismaSchemaInfo } from './types';
/**
* Resolves Prisma schema information from the client
*
* This class analyzes the Prisma client to extract model definitions,
* field types, relationships, and other metadata needed for dynamic SQL generation.
*/
export declare class PrismaSchemaResolver {
private readonly options;
private schemaInfo?;
constructor(options: RawSqlClientOptions);
/**
* Resolve complete schema information from Prisma client
*
* @param prisma - The Prisma client instance
* @returns Complete schema information
*/
resolveSchema(prisma: PrismaClientType): Promise<PrismaSchemaInfo>;
/**
* Create a TableColumnResolver function for rawsql-ts
*
* @returns TableColumnResolver function
*/
createTableColumnResolver(): TableColumnResolver;
/**
* Get all available table names
*
* @returns Array of table names
*/
getTableNames(): string[];
/**
* Get all column names for a specific table
*
* @param tableName - The table name
* @returns Array of column names, or undefined if table not found
*/
getColumnNames(tableName: string): string[] | undefined;
/**
* Check if a table exists in the schema
*
* @param tableName - The table name to check
* @returns true if table exists, false otherwise
*/
hasTable(tableName: string): boolean;
/**
* Check if a column exists in a specific table
*
* @param tableName - The table name
* @param columnName - The column name to check
* @returns true if column exists, false otherwise
*/
hasColumn(tableName: string, columnName: string): boolean;
/**
* Get DMMF directly from schema.prisma file
*
* @returns Promise resolving to DMMF object or null if not found
*/
private getDMMFFromSchema;
/**
* Find schema.prisma file in common locations
*
* @returns Promise resolving to schema file path or null if not found
*/
private findSchemaFile;
/**
* Find schema file synchronously
*
* @returns Path to schema.prisma file or null if not found
*/
private findSchemaFileSync;
/**
* Extract DMMF from Prisma client using various access methods
* Supports multiple Prisma versions and deployment environments
*/
private extractDmmfFromClient;
/**
* Validate if the extracted object is a valid DMMF
*/
private isValidDmmf;
/**
* Parse model information from Prisma DMMF
*
* @param dmmf - Data Model Meta Format from Prisma
* @returns Parsed model information
*/
private parseModelsFromDmmf;
/**
* Get table name with custom mappings applied
*/
private getTableName;
/**
* Parse field information from model
*/
private parseFieldsFromModel;
/**
* Get column name with custom mappings applied
*/
private getColumnName;
/**
* Parse relation information from model
*/
private parseRelationsFromModel;
/**
* Determine relation type from field information
*/
private determineRelationType;
/**
* Extract primary key fields from model
*/
private extractPrimaryKey;
/**
* Extract unique constraints from model
*/
private extractUniqueConstraints;
/**
* Find model by table name
*
* @param tableName - The table name to search for
* @returns Model information if found, undefined otherwise
*/
private findModelByTableName;
/**
* Get model information by model name
*
* @param modelName - The Prisma model name
* @returns Model information if found, undefined otherwise
*/
getModelInfo(modelName: string): PrismaModelInfo | undefined;
/**
* Get all model names
*
* @returns Array of model names
*/
getModelNames(): string[];
/**
* Extract database provider from DMMF
*
* @param dmmf - The DMMF object
* @returns Database provider string (postgresql, mysql, sqlite, etc.)
*/
private extractDatabaseProvider;
}