import { DbContext } from '../orm/db-context'; /********************************* * [元数据生成顺序] * code first: * 装饰器(Constructor) => Model => Schema * db first: * SchemaReader => Schema => Model * * 推荐使用code first模式,因为db first仅可生成表和列, * 关联关系等因缺乏信息完美无法生成,需要手动添加 **********************************/ /** * 外键架构 */ export interface ForeignKeySchema { /** * 外键名称 */ name: string; /** * 列对应 */ columns: string[]; /** * 主键表 */ referenceTable: string; /** * 主键表所在架构 */ referenceSchema?: string; /** * 引用列(主键列) */ referenceColumns: string[]; /** * 级联删除 * // WARN 慎用 */ isCascade?: boolean; comment?: string; } export interface DatabaseSchema { /** * 数据库名称 */ name: string; /** * 排序规则 */ collate?: string; /** * 表 */ tables: TableSchema[]; /** * 架构 */ schemas: string[]; /** * 视图 */ views: ViewSchema[]; /** * 存储过程列表 */ procedures: ProcedureSchema[]; /** * 函数列表 */ functions: FunctionSchema[]; /** * 序列 */ sequences: SequenceSchema[]; /** * 摘要说明 */ comment?: string; } export interface FunctionSchema { comment?: string; name: string; schema?: string; scripts: string; } export interface ProcedureSchema { name: string; schema?: string; scripts: string; comment?: string; } /** * 实体表架构声明 */ export interface TableSchema { /** * 数据库对象名称 */ name: string; /** * 所在架构 */ schema?: string; /** * 摘要说明 */ comment?: string; /** * 列 */ columns: ColumnSchema[]; /** * 索引,不包含主键约束及uniq约束等 */ indexes: IndexSchema[]; primaryKey?: PrimaryKeySchema; /** * 外键 */ foreignKeys: ForeignKeySchema[]; /** * 约束:包含检查约束及,不含主键、唯一健、外键、及索引 */ constraints: ConstraintSchema[]; /** * 初始数据 */ seedData?: object[]; } export interface SequenceSchema { comment?: string; type: string; name: string; schema?: string; startValue: number; increment: number; } export interface CheckConstraintSchema { kind: 'CHECK'; name: string; sql: string; comment?: string; } export interface KeyColumnSchema { name: string; isAscending: boolean; } export interface PrimaryKeySchema { name: string; /** * 是否是非聚焦索引 */ isNonclustered: boolean; comment?: string; columns: KeyColumnSchema[]; } export declare type ConstraintSchema = CheckConstraintSchema; /** * 视图架构 */ export interface ViewSchema { /** * 视图名称 */ name: string; /** * 所在架构 */ schema?: string; /** * 声明语句 */ scripts: string; /** * 摘要说明 */ comment?: string; } /** * 列架构 */ export interface ColumnSchema { /** * 字段名 */ name: string; /** * 数据类型 */ type: string; /** * 是否可空 */ isNullable: boolean; /** * 默认值 */ defaultValue?: string; /** * 是否标识列 */ isIdentity: boolean; /** * 标识列种子 */ identityStartValue?: number; /** * 标识列步长 */ identityIncrement?: number; /** * 是否计算列 */ isCalculate: boolean; /** * 是否行标识列 */ isRowflag: boolean; /** * 计算表达式 */ calculateExpression?: string; /** * 摘要说明 */ comment?: string; } /** * 索引 */ export interface IndexSchema { name: string; isUnique: boolean; /** * 是否是聚焦索引 */ isClustered: boolean; /** * 索引列 */ columns: KeyColumnSchema[]; comment?: string; } /** * 从Metadata生成架构 * @param sqlifier * @param context * @returns */ export declare function generateSchema(context: DbContext): DatabaseSchema;