@adonisjs/lucid
Version:
SQL ORM built on top of Active Record pattern
78 lines (77 loc) • 2.58 kB
TypeScript
import type { SchemaRules, DatabaseTable, GeneratedSchemas } from '../../types/schema_generator.ts';
import { type QueryClientContract } from '../../types/database.ts';
/**
* OrmSchemaBuilder handles the core logic of generating TypeScript
* model schemas from database table structures.
*/
export declare class OrmSchemaBuilder {
private client;
/**
* Schema rules for type mapping and customization
*/
private schema;
/**
* Mapping from database types to internal type identifiers
*/
private dataTypes;
constructor(client: QueryClientContract);
/**
* Load user-defined schema rules
*/
loadRules(rules: SchemaRules[]): void;
/**
* Returns true when the table is in the default schema of the
* dialect, or when the dialect has no schemas
*/
private isInDefaultSchema;
/**
* Returns the table name with its schema, when the table has one
*/
private getQualifiedName;
/**
* Returns the "tables" rules of the table. The rules of
* "<schema>.<table>" come first, so that they win over the
* rules of the table name.
*/
private getTableRules;
/**
* Returns the class name of each table, in the order of the tables.
*
* The first pass collects the class names of the tables in the default
* schema. The second pass prefixes the class of a table of another
* schema with its schema name, when a table of the default schema or
* another table outside the default schema gives the same class name.
* A class name that is already taken raises an exception, because the
* output file would declare the same class twice.
*/
private getClassNames;
/**
* Serialize a decorator argument value to a TypeScript-safe string
*/
private serializeArgValue;
/**
* Build a decorator string from a structured DecoratorInfo
*/
private buildDecorator;
/**
* Build decorator strings from a ColumnInfo. Supports both the
* new `decorators` array and the deprecated `decorator` string.
*/
private buildDecorators;
/**
* Generate schema for a single column
*/
private generateColumnSchema;
/**
* Generate schema for a single table (internal method)
*/
private generateTableSchema;
/**
* Generate schemas for multiple tables
*/
generateSchemas(tables: DatabaseTable[]): GeneratedSchemas;
/**
* Get the final output string from generated schemas
*/
getOutput(schemas: GeneratedSchemas): string;
}