import { TFlatType, Type, UnwrappedType } from "@simplysm/sd-core-common"; import { DbContext } from "./DbContext"; import { Queryable } from "./query/queryable/Queryable"; export type TSdOrmDataType = | ISdOrmDataTypeOfText | ISdOrmDataTypeOfDecimal | ISdOrmDataTypeOfString | ISdOrmDataTypeOfFixString | ISdOrmDataTypeOfBinary; export interface ISdOrmDataTypeOfText { type: "TEXT"; } export interface ISdOrmDataTypeOfDecimal { type: "DECIMAL"; precision: number; digits?: number; } export interface ISdOrmDataTypeOfString { type: "STRING"; length?: number | "MAX"; } export interface ISdOrmDataTypeOfFixString { type: "FIXSTRING"; length: number; } export interface ISdOrmDataTypeOfBinary { type: "BINARY"; length?: number | "MAX"; } export type TQueryValue = TFlatType; export type TStrippedQueryValue = UnwrappedType; //region decorator export interface ITableNameDef { database?: string; schema?: string; name: string; } export interface ITableDef extends ITableNameDef { description: string; columns: IColumnDef[]; foreignKeys: IForeignKeyDef[]; foreignKeyTargets: IForeignKeyTargetDef[]; indexes: IIndexDef[]; referenceKeys: IReferenceKeyDef[]; referenceKeyTargets: IReferenceKeyTargetDef[]; view?: (db: any) => Queryable; procedure?: string; } export interface IColumnDef { description?: string; propertyKey: string; name: string; dataType?: Type | TSdOrmDataType | string; nullable?: boolean; autoIncrement?: boolean; primaryKey?: number; typeFwd: () => Type; } export interface IForeignKeyDef { description?: string; propertyKey: string; name: string; columnPropertyKeys: string[]; targetTypeFwd: () => Type; } export interface IForeignKeyTargetDef { description?: string; propertyKey: string; name: string; sourceKeyPropertyKey: string; isSingle: boolean; sourceTypeFwd: () => Type; } export interface IIndexDef { description?: string; name: string; columns: { columnPropertyKey: string; order: number; orderBy: "ASC" | "DESC"; unique: boolean; }[]; } export interface IReferenceKeyDef { description?: string; propertyKey: string; name: string; columnPropertyKeys: string[]; targetTypeFwd: () => Type; } export interface IReferenceKeyTargetDef { description?: string; propertyKey: string; name: string; sourceKeyPropertyKey: string; isSingle: boolean; sourceTypeFwd: () => Type; } //endregion export interface IDbMigration { up(db: DbContext): Promise; }