import type { T } from "./UtilityTypes"; import { Model } from "./Model"; type ExtendType = NumberConstructor | StringConstructor | BooleanConstructor | DateConstructor | readonly ExtendType[] | { [_: string]: ExtendType; }; type ResolveType = T extends NumberConstructor ? number : T extends StringConstructor ? string : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends readonly (infer U)[] ? [U] extends [never] ? any[] : ResolveType[] : T extends Record ? { [K in keyof T]: ResolveType; } : never; /** * Class 'Blueprint' is used to make the schema for table * @example * import { Schema , Blueprint } from 'tspace-mysql' * import sql from '../../../build/lib/core/SqlLike'; * await new Schema().table('users',{ * id : Blueprint.int().notNull().primary().autoIncrement(), * name : Blueprint.varchar(255).default('my name').index(), * email : Blueprint.varchar(255).unique().compositeIndex(['verify']), // composite index email,verify * json : Blueprint.json().null(), * verify : Blueprint.tinyInt(1).notNull(), * created_at : Blueprint.timestamp().null(), * updated_at : Blueprint.timestamp().null(), * deleted_at : Blueprint.timestamp().null() * }) */ declare class Blueprint { private _default; private _enum; private _type; private _attributes; private _foreignKey; private _index; private _compositeIndex; private _compositeUnique; private _column; private _isVirtual; private _isEnum; private _isNull; private _sql; private _valueType; /** * Assign type 'virtual' to column * @static * @return {Blueprint} Blueprint */ static virtualColumn(sql: string | { select?: string; where?: string; orderBy?: string; groupBy?: string; }): Blueprint; /** * Assign type 'virtual' to column * @static * @return {Blueprint} Blueprint */ virtualColumn(sql: string | { select?: string; where?: string; orderBy?: string; groupBy?: string; }): Blueprint; /** * Assign type 'serial' in table * @static * @return {Blueprint} Blueprint */ static serial(_?: number): Blueprint; /** * Assign type 'serial' in table * @return {Blueprint} Blueprint */ serial(_?: number): Blueprint; /** * Assign type 'INT' in table * @static * @return {Blueprint} Blueprint */ static int(_?: number): Blueprint; /** * Assign type 'INT' in table * @return {Blueprint} Blueprint */ int(_?: number): Blueprint; /** * Assign type 'INT' in table * @static * @return {Blueprint} Blueprint */ static integer(_?: number): Blueprint; /** * Assign type 'INT' in table * @return {Blueprint} Blueprint */ integer(_?: number): Blueprint; /** * Assign type 'TINYINT' in table * @static * @param {number} number * @return {Blueprint} Blueprint */ static tinyInt(number?: number): Blueprint; /** * Assign type 'TINYINT' in table * @param {number} number * @return {Blueprint} Blueprint */ tinyInt(number?: number): Blueprint; /** * Assign type 'TINYINT' in table * @static * @param {number} number * @return {Blueprint} Blueprint */ static tinyint(number?: number): Blueprint; /** * Assign type 'TINYINT' in table * @param {number} number * @return {Blueprint} Blueprint */ tinyint(number?: number): Blueprint; /** * Assign type 'BIGINT' in table * @static * @param {number} number [number = 10] * @return {Blueprint} Blueprint */ static bigInt(number?: number): Blueprint; /** * Assign type 'BIGINT' in table * @param {number} number [number = 10] * @return {Blueprint} Blueprint */ bigInt(number?: number): Blueprint; /** * Assign type 'BIGINT' in table * @static * @param {number} number [number = 10] * @return {Blueprint} Blueprint */ static bigint(number?: number): Blueprint; /** * Assign type 'BIGINT' in table * @param {number} number [number = 10] * @return {Blueprint} Blueprint */ bigint(number?: number): Blueprint; /** * Assign type 'BOOLEAN' in table * @static * @return {Blueprint} Blueprint */ static boolean(): Blueprint; /** * Assign type 'BOOLEAN' in table * @return {Blueprint} Blueprint */ boolean(): Blueprint; /** * Assign type 'DOUBLE' in table * @static * @param {number} length between 1-255 * @param {number} decimal 0.000...n * @return {Blueprint} Blueprint */ static double(length?: number, decimal?: number): Blueprint; /** * Assign type 'DOUBLE' in table * @param {number} length between 1-255 * @param {number} decimal 0.000...n * @return {Blueprint} Blueprint */ double(length?: number, decimal?: number): Blueprint; /** * Assign type 'FLOAT' in table * @static * @param {number} length between 1-255 * @param {number} decimal 0.000...n * @return {Blueprint} Blueprint */ static float(length?: number, decimal?: number): Blueprint; /** * Assign type 'FLOAT' in table * @param {number} length between 1-255 * @param {number} decimal 0.000...n * @return {Blueprint} Blueprint */ float(length?: number, decimal?: number): Blueprint; /** * Assign type 'VARCHAR' in table * @static * @param {number} length [length = 191] length of string * @return {Blueprint} Blueprint */ static varchar(length?: number): Blueprint; /** * Assign type 'VARCHAR' in table * @param {number} length [length = 191] length of string * @return {Blueprint} Blueprint */ varchar(length?: number): Blueprint; /** * Assign type 'UUID' in table * @static * @return {Blueprint} Blueprint */ static uuid(): Blueprint; /** * Assign type 'UUID' in table * @return {Blueprint} Blueprint */ uuid(): Blueprint; /** * Assign type 'CHAR' in table * @static * @param {number} length [length = 1] length of string * @return {Blueprint} Blueprint */ static char(length?: number): Blueprint; /** * Assign type 'CHAR' in table * @param {number} length [length = 1] length of string * @return {Blueprint} Blueprint */ char(length?: number): Blueprint; /** * Assign type 'LONGTEXT' in table * @static * @return {Blueprint} Blueprint */ static longText(): Blueprint; /** * Assign type 'LONGTEXT' in table * @return {Blueprint} Blueprint */ longText(): Blueprint; /** * Assign type 'LONGTEXT' in table * @static * @return {Blueprint} Blueprint */ static longtext(): Blueprint; /** * Assign type 'LONGTEXT' in table * @return {Blueprint} Blueprint */ longtext(): Blueprint; /** * Assign type 'BINARY' in table * @static * @return {Blueprint} Blueprint */ static binary(): Blueprint; /** * Assign type 'BINARY' in table * @return {Blueprint} Blueprint */ binary(): Blueprint; /** * Assign type 'JSON' in table * @static * @return {Blueprint} Blueprint */ static json(): Blueprint; /** * Assign type 'JSON' in table * @return {Blueprint} Blueprint */ json(): Blueprint; /** * Assign type 'MEDIUMTEXT' in table * @static * @return {Blueprint} Blueprint */ static mediumText(): Blueprint; /** * Assign type 'MEDIUMTEXT' in table * @return {Blueprint} Blueprint */ mediumText(): Blueprint; /** * Assign type 'MEDIUMTEXT' in table * @static * @return {Blueprint} Blueprint */ static mediumtext(): Blueprint; /** * Assign type 'MEDIUMTEXT' in table * @return {Blueprint} Blueprint */ mediumtext(): Blueprint; /** * Assign type 'TINYTEXT' in table * @static * @return {Blueprint} Blueprint */ static tinyText(): Blueprint; /** * Assign type 'TINYTEXT' in table * @return {Blueprint} Blueprint */ tinyText(): Blueprint; /** * Assign type 'TINYTEXT' in table * @static * @return {Blueprint} Blueprint */ static tinytext(): Blueprint; /** * Assign type 'TINYTEXT' in table * @return {Blueprint} Blueprint */ tinytext(): Blueprint; /** * Assign type 'TEXT' in table * @static * @return {Blueprint} Blueprint */ static text(): Blueprint; /** * Assign type 'TEXT' in table * @return {Blueprint} Blueprint */ text(): Blueprint; /** * Assign type 'ENUM' * @static * @param {...string} enums n1, n2, n3, ...n * @return {Blueprint} Blueprint */ static enum>(...enums: K[]): Blueprint; /** * Assign type 'ENUM' * @param {...string} enums n1, n2, n3, ...n * @return {Blueprint} Blueprint */ enum>(...enums: K[]): Blueprint; /** * Assign type 'DATE' in table * @static * @return {Blueprint} Blueprint */ static date(): Blueprint; /** * Assign type 'DATE' in table * @return {Blueprint} Blueprint */ date(): Blueprint; /** * Assign type 'DATETIME' in table * @static * @return {Blueprint} Blueprint */ static dateTime(): Blueprint; /** * Assign type 'DATETIME' in table * @return {Blueprint} Blueprint */ dateTime(): Blueprint; /** * Assign type 'DATETIME' in table * @static * @return {Blueprint} Blueprint */ static datetime(): Blueprint; /** * Assign type 'DATETIME' in table * @return {Blueprint} Blueprint */ datetime(): Blueprint; /** * Assign type 'TIMESTAMP' in table * @static * @return {Blueprint} Blueprint */ static timestamp(): Blueprint; /** * Assign type 'TIMESTAMP' in table * @return {Blueprint} Blueprint */ timestamp(): Blueprint; /** * Assign 'raw' in table * @static * @param {object} opts * @property {string} opts.select * @property {string | undefined} opts.where * @return {Blueprint} Blueprint * @example * const schema = { * raw : Blueprint.raw({ type : 'DECIMAL(10, 2)' , attribute : 'DEFAULT(1)'}), * enums : Blueprint.raw({ type : `ENUM('pending', 'active', 'banned')` , attribute : `DEFAULT 'pending'`}), * } */ static raw(opts: { type: string; attribute?: string; }): Blueprint; /** * Assign 'raw' in table * @param {object} opts * @property {string} opts.select * @property {string | undefined} opts.where * @return {Blueprint} Blueprint * * @example * const schema = { * raw : Blueprint.raw({ type : 'DECIMAL(10, 2)' , attribute : 'DEFAULT(1)'}), * enums : Blueprint.raw({ type : `ENUM('pending', 'active', 'banned')` , attribute : `DEFAULT 'pending'`}), * } */ raw(opts: { type: string; attribute?: string; }): Blueprint; /** * Assign attributes 'UNSIGNED' in table * @return {Blueprint} Blueprint */ unsigned(): Blueprint; /** * Assign attributes 'UNIQUE' in table * @return {Blueprint} Blueprint */ unique(): Blueprint; /** * Assign attributes 'UNIQUE' in table * @return {Blueprint} Blueprint */ compositeUnique(columns: string[], name?: string): Blueprint; /** * Assign attributes 'NULL' in table * @return {Blueprint} Blueprint */ null(): Blueprint; /** * Assign attributes 'NOT NULL' in table * @return {Blueprint} Blueprint */ notNull(): Blueprint>; /** * Assign attributes 'NOT NULL' in table * @return {Blueprint} Blueprint */ notnull(): Blueprint>; /** * Assign attributes 'PRIMARY KEY' in table * @return {Blueprint} Blueprint */ primary(): Blueprint; /** * Assign attributes 'default' in table * @param {string | number} value default value * @return {Blueprint} Blueprint */ default(value: I): Blueprint>; /** * Assign attributes 'default currentTimestamp' in table * @return {Blueprint} Blueprint */ currentTimestamp(): Blueprint; /** * Assign attributes 'default currentTimestamp' in table * @return {Blueprint} Blueprint */ currenttimestamp(): Blueprint; /** * Assign attributes 'autoIncrement' in table * @return {Blueprint} Blueprint */ autoIncrement(): Blueprint; /** * Assign attributes 'autoIncrement' in table * @return {Blueprint} Blueprint */ autoincrement(): Blueprint; /** * Assign attributes 'foreign' in table * Reference bettwen Column Main to Column Child * @param {object} property object { key , value , operator } * @property {string?} property.reference * @property {Model | string} property.on * @property {string?} property.onDelete * @property {string?} property.onUpdate * @return {Blueprint} Blueprint */ foreign({ references, on, onDelete, onUpdate, }: { references?: string; on: (() => new () => Model) | string; onDelete?: "CASCADE" | "NO ACTION" | "RESTRICT" | "SET NULL"; onUpdate?: "CASCADE" | "NO ACTION" | "RESTRICT" | "SET NULL"; }): Blueprint; /** * Assign attributes 'index' in table * @param {string} name of index * @return {Blueprint} Blueprint */ index(name?: string): Blueprint; /** * Assign attributes 'index' in table * @param {string} name of index * @return {Blueprint} Blueprint */ compositeIndex(columns: string[], name?: string): Blueprint; /** * Assign type to blueprint * @param {NumberConstructor|StringConstructor|BooleanConstructor|DateConstructor} type * @return {Blueprint} Blueprint */ transform(_: T): Blueprint>; get sql(): { select?: string; where?: string; orderBy?: string; groupBy?: string; } | null; get column(): string | null; get type(): string; get attributes(): string[]; get foreignKey(): Record | null; get indexKey(): string | null; get compositeIndexKey(): { columns: string[]; name?: string; } | null; get compositeUniqueKey(): { columns: string[]; name?: string; } | null; get defaultValue(): string | number | boolean | null; get valueType(): ExtendType; get enums(): string[]; get isVirtual(): boolean; get isEnum(): boolean; get isNull(): boolean; private _addAssignType; private _addAssignAttribute; } export { Blueprint }; export default Blueprint;