UNPKG

lakutata

Version:

An IoC-based universal application framework.

466 lines (457 loc) 12.6 kB
import { TableColumnOptions, TableForeignKeyOptions, TableUniqueOptions, TableCheckOptions, TableExclusionOptions, TableIndexOptions, TableOptions } from './TypeDef.internal.91.js'; import { ForeignKeyMetadata, UniqueMetadata, CheckMetadata, ExclusionMetadata, IndexMetadata, EntityMetadata } from './TypeDef.internal.47.js'; import { Driver } from './TypeDef.internal.45.js'; /** * Table's columns in the database represented in this class. */ declare class TableColumn { readonly "@instanceof": symbol; /** * Column name. */ name: string; /** * Column type. */ type: string; /** * Column's default value. */ default?: any; /** * ON UPDATE trigger. Works only for MySQL. */ onUpdate?: string; /** * Indicates if column is NULL, or is NOT NULL in the database. */ isNullable: boolean; /** * Indicates if column is auto-generated sequence. */ isGenerated: boolean; /** * Specifies generation strategy if this column will use auto increment. * `rowid` option supported only in CockroachDB. */ generationStrategy?: "uuid" | "increment" | "rowid" | "identity"; /** * Indicates if column is a primary key. */ isPrimary: boolean; /** * Indicates if column has unique value. */ isUnique: boolean; /** * Indicates if column stores array. */ isArray: boolean; /** * Column's comment. */ comment?: string; /** * Column type's length. Used only on some column types. * For example type = "string" and length = "100" means that ORM will create a column with type varchar(100). */ length: string; /** * Column type's display width. Used only on some column types in MySQL. * For example, INT(4) specifies an INT with a display width of four digits. */ width?: number; /** * Defines column character set. */ charset?: string; /** * Defines column collation. */ collation?: string; /** * The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum * number of digits that are stored for the values. */ precision?: number | null; /** * The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number * of digits to the right of the decimal point and must not be greater than precision. */ scale?: number; /** * Puts ZEROFILL attribute on to numeric column. Works only for MySQL. * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column */ zerofill: boolean; /** * Puts UNSIGNED attribute on to numeric column. Works only for MySQL. */ unsigned: boolean; /** * Array of possible enumerated values. */ enum?: string[]; /** * Exact name of enum */ enumName?: string; /** * Name of the primary key constraint for primary column. */ primaryKeyConstraintName?: string; /** * Generated column expression. */ asExpression?: string; /** * Generated column type. */ generatedType?: "VIRTUAL" | "STORED"; /** * Identity column type. Supports only in Postgres 10+. */ generatedIdentity?: "ALWAYS" | "BY DEFAULT"; /** * Spatial Feature Type (Geometry, Point, Polygon, etc.) */ spatialFeatureType?: string; /** * SRID (Spatial Reference ID (EPSG code)) */ srid?: number; constructor(options?: TableColumnOptions); /** * Clones this column to a new column with exact same properties as this column has. */ clone(): TableColumn; } /** * Foreign key from the database stored in this class. */ declare class TableForeignKey { readonly "@instanceof": symbol; /** * Name of the foreign key constraint. */ name?: string; /** * Column names which included by this foreign key. */ columnNames: string[]; /** * Database of Table referenced in the foreign key. */ referencedDatabase?: string; /** * Database of Table referenced in the foreign key. */ referencedSchema?: string; /** * Table referenced in the foreign key. */ referencedTableName: string; /** * Column names which included by this foreign key. */ referencedColumnNames: string[]; /** * "ON DELETE" of this foreign key, e.g. what action database should perform when * referenced stuff is being deleted. */ onDelete?: string; /** * "ON UPDATE" of this foreign key, e.g. what action database should perform when * referenced stuff is being updated. */ onUpdate?: string; /** * Set this foreign key constraint as "DEFERRABLE" e.g. check constraints at start * or at the end of a transaction */ deferrable?: string; constructor(options: TableForeignKeyOptions); /** * Creates a new copy of this foreign key with exactly same properties. */ clone(): TableForeignKey; /** * Creates a new table foreign key from the given foreign key metadata. */ static create(metadata: ForeignKeyMetadata, driver: Driver): TableForeignKey; } /** * Database's table unique constraint stored in this class. */ declare class TableUnique { readonly "@instanceof": symbol; /** * Constraint name. */ name?: string; /** * Columns that contains this constraint. */ columnNames: string[]; /** * Set this foreign key constraint as "DEFERRABLE" e.g. check constraints at start * or at the end of a transaction */ deferrable?: string; constructor(options: TableUniqueOptions); /** * Creates a new copy of this constraint with exactly same properties. */ clone(): TableUnique; /** * Creates unique from the unique metadata object. */ static create(uniqueMetadata: UniqueMetadata): TableUnique; } /** * Database's table check constraint stored in this class. */ declare class TableCheck { readonly "@instanceof": symbol; /** * Constraint name. */ name?: string; /** * Column that contains this constraint. */ columnNames?: string[]; /** * Check expression. */ expression?: string; constructor(options: TableCheckOptions); /** * Creates a new copy of this constraint with exactly same properties. */ clone(): TableCheck; /** * Creates checks from the check metadata object. */ static create(checkMetadata: CheckMetadata): TableCheck; } /** * Database's table exclusion constraint stored in this class. */ declare class TableExclusion { readonly "@instanceof": symbol; /** * Constraint name. */ name?: string; /** * Exclusion expression. */ expression?: string; constructor(options: TableExclusionOptions); /** * Creates a new copy of this constraint with exactly same properties. */ clone(): TableExclusion; /** * Creates exclusions from the exclusion metadata object. */ static create(exclusionMetadata: ExclusionMetadata): TableExclusion; } /** * Database's table index stored in this class. */ declare class TableIndex { readonly "@instanceof": symbol; /** * Index name. */ name?: string; /** * Columns included in this index. */ columnNames: string[]; /** * Indicates if this index is unique. */ isUnique: boolean; /** * The SPATIAL modifier indexes the entire column and does not allow indexed columns to contain NULL values. * Works only in MySQL. */ isSpatial: boolean; /** * Create the index using the CONCURRENTLY modifier * Works only in postgres. */ isConcurrent: boolean; /** * The FULLTEXT modifier indexes the entire column and does not allow prefixing. * Works only in MySQL. */ isFulltext: boolean; /** * NULL_FILTERED indexes are particularly useful for indexing sparse columns, where most rows contain a NULL value. * In these cases, the NULL_FILTERED index can be considerably smaller and more efficient to maintain than * a normal index that includes NULL values. * * Works only in Spanner. */ isNullFiltered: boolean; /** * Fulltext parser. * Works only in MySQL. */ parser?: string; /** * Index filter condition. */ where: string; constructor(options: TableIndexOptions); /** * Creates a new copy of this index with exactly same properties. */ clone(): TableIndex; /** * Creates index from the index metadata object. */ static create(indexMetadata: IndexMetadata): TableIndex; } /** * Table in the database represented in this class. */ declare class Table { readonly "@instanceof": symbol; /** * Database name that this table resides in if it applies. */ database?: string; /** * Schema name that this table resides in if it applies. */ schema?: string; /** * May contain database name, schema name and table name, unless they're the current database. * * E.g. myDB.mySchema.myTable */ name: string; /** * Table columns. */ columns: TableColumn[]; /** * Table indices. */ indices: TableIndex[]; /** * Table foreign keys. */ foreignKeys: TableForeignKey[]; /** * Table unique constraints. */ uniques: TableUnique[]; /** * Table check constraints. */ checks: TableCheck[]; /** * Table exclusion constraints. */ exclusions: TableExclusion[]; /** * Indicates if table was just created. * This is needed, for example to check if we need to skip primary keys creation * for new tables. */ justCreated: boolean; /** * Enables Sqlite "WITHOUT ROWID" modifier for the "CREATE TABLE" statement */ withoutRowid?: boolean; /** * Table engine. */ engine?: string; /** * Table comment. Not supported by all database types. */ comment?: string; constructor(options?: TableOptions); get primaryColumns(): TableColumn[]; /** * Clones this table to a new table with all properties cloned. */ clone(): Table; /** * Add column and creates its constraints. */ addColumn(column: TableColumn): void; /** * Remove column and its constraints. */ removeColumn(column: TableColumn): void; /** * Adds unique constraint. */ addUniqueConstraint(uniqueConstraint: TableUnique): void; /** * Removes unique constraint. */ removeUniqueConstraint(removedUnique: TableUnique): void; /** * Adds check constraint. */ addCheckConstraint(checkConstraint: TableCheck): void; /** * Removes check constraint. */ removeCheckConstraint(removedCheck: TableCheck): void; /** * Adds exclusion constraint. */ addExclusionConstraint(exclusionConstraint: TableExclusion): void; /** * Removes exclusion constraint. */ removeExclusionConstraint(removedExclusion: TableExclusion): void; /** * Adds foreign keys. */ addForeignKey(foreignKey: TableForeignKey): void; /** * Removes foreign key. */ removeForeignKey(removedForeignKey: TableForeignKey): void; /** * Adds index. */ addIndex(index: TableIndex, isMysql?: boolean): void; /** * Removes index. */ removeIndex(tableIndex: TableIndex, isMysql?: boolean): void; findColumnByName(name: string): TableColumn | undefined; /** * Returns all column indices. */ findColumnIndices(column: TableColumn): TableIndex[]; /** * Returns all column foreign keys. */ findColumnForeignKeys(column: TableColumn): TableForeignKey[]; /** * Returns all column uniques. */ findColumnUniques(column: TableColumn): TableUnique[]; /** * Returns all column checks. */ findColumnChecks(column: TableColumn): TableCheck[]; /** * Creates table from a given entity metadata. */ static create(entityMetadata: EntityMetadata, driver: Driver): Table; } export { Table, TableCheck, TableColumn, TableExclusion, TableForeignKey, TableIndex, TableUnique };