lakutata
Version:
An IoC-based universal application framework.
792 lines (765 loc) • 24.2 kB
TypeScript
import { OnDeleteType, OnUpdateType, DeferrableType } from './TypeDef.internal.73.js';
import { ColumnType, Geometry, PrimaryGeneratedColumnType } from './TypeDef.internal.44.js';
import { OrderByCondition } from './TypeDef.internal.74.js';
import './TypeDef.internal.30.js';
import { SelectQueryBuilder } from './TypeDef.internal.38.js';
import { DataSource } from './TypeDef.internal.33.js';
/**
* Describes all relation's options.
*/
interface RelationOptions {
/**
* Sets cascades options for the given relation.
* If set to true then it means that related object can be allowed to be inserted or updated in the database.
* You can separately restrict cascades to insertion or updation using following syntax:
*
* cascade: ["insert", "update", "remove", "soft-remove", "recover"] // include or exclude one of them
*/
cascade?: boolean | ("insert" | "update" | "remove" | "soft-remove" | "recover")[];
/**
* Indicates if relation column value can be nullable or not.
*/
nullable?: boolean;
/**
* Database cascade action on delete.
*/
onDelete?: OnDeleteType;
/**
* Database cascade action on update.
*/
onUpdate?: OnUpdateType;
/**
* Indicate if foreign key constraints can be deferred.
*/
deferrable?: DeferrableType;
/**
* Indicates whether foreign key constraints will be created for join columns.
* Can be used only for many-to-one and owner one-to-one relations.
* Defaults to true.
*/
createForeignKeyConstraints?: boolean;
/**
* Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise
* which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.
*/
lazy?: boolean;
/**
* Set this relation to be eager.
* Eager relations are always loaded automatically when relation's owner entity is loaded using find* methods.
* Only using QueryBuilder prevents loading eager relations.
* Eager flag cannot be set from both sides of relation - you can eager load only one side of the relationship.
*/
eager?: boolean;
/**
* Indicates if persistence is enabled for the relation.
* By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.
* If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.
* This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.
*/
persistence?: boolean;
/**
* When a parent is saved (with cascading but) without a child row that still exists in database, this will control what shall happen to them.
* delete will remove these rows from database.
* nullify will remove the relation key.
* disable will keep the relation intact. Removal of related item is only possible through its own repo.
*/
orphanedRowAction?: "nullify" | "delete" | "soft-delete" | "disable";
}
/**
* Interface for objects that deal with (un)marshalling data.
*/
interface ValueTransformer {
/**
* Used to marshal data when writing to the database.
*/
to(value: any): any;
/**
* Used to unmarshal data when reading from the database.
*/
from(value: any): any;
}
/**
* Column options specific to all column types.
*/
interface ColumnCommonOptions {
/**
* Indicates if column is always selected by QueryBuilder and find operations.
* Default value is "true".
*/
select?: boolean;
/**
* Column name in the database.
*/
name?: string;
/**
* Indicates if this column is a primary key.
* Same can be achieved when @PrimaryColumn decorator is used.
*/
primary?: boolean;
/**
* Specifies if this column will use auto increment (sequence, generated identity, rowid).
* Note that in some databases only one column in entity can be marked as generated, and it must be a primary column.
*/
generated?: boolean | "increment" | "uuid" | "rowid" | "identity";
/**
* Specifies if column's value must be unique or not.
*/
unique?: boolean;
/**
* Indicates if column's value can be set to NULL.
*/
nullable?: boolean;
/**
* Default database value.
* Note that default value is not supported when column type is 'json' of mysql.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* Column comment. Not supported by all database types.
*/
comment?: string;
/**
* Indicates if this column is an array.
* Can be simply set to true or array length can be specified.
* Supported only by postgres.
*/
array?: boolean;
/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
}
/**
* Describes all column's options.
*/
interface ColumnOptions extends ColumnCommonOptions {
/**
* Column type. Must be one of the value from the ColumnTypes class.
*/
type?: ColumnType;
/**
* Column name in the database.
*/
name?: 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 | number;
/**
* 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;
/**
* Indicates if column's value can be set to NULL.
* Default value is "false".
*/
nullable?: boolean;
/**
* Indicates if column value is not updated by "save" operation.
* It means you'll be able to write this value only when you first time insert the object.
* Default value is "false".
*
* @deprecated Please use the `update` option instead. Careful, it takes
* the opposite value to readonly.
*
*/
readonly?: boolean;
/**
* Indicates if column value is updated by "save" operation.
* If false, you'll be able to write this value only when you first time insert the object.
* Default value is "true".
*/
update?: boolean;
/**
* Indicates if column is always selected by QueryBuilder and find operations.
* Default value is "true".
*/
select?: boolean;
/**
* Indicates if column is inserted by default.
* Default value is "true".
*/
insert?: boolean;
/**
* Default database value.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: string;
/**
* Indicates if this column is a primary key.
* Same can be achieved when @PrimaryColumn decorator is used.
*/
primary?: boolean;
/**
* Specifies if column's value must be unique or not.
*/
unique?: boolean;
/**
* Column comment. Not supported by all database types.
*/
comment?: 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 this column
*/
zerofill?: boolean;
/**
* Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
*/
unsigned?: boolean;
/**
* Defines a column character set.
* Not supported by all database types.
*/
charset?: string;
/**
* Defines a column collation.
*/
collation?: string;
/**
* Array of possible enumerated values.
*/
enum?: (string | number)[] | Object;
/**
* Exact name of enum
*/
enumName?: string;
/**
* If this column is primary key then this specifies the name for it.
*/
primaryKeyConstraintName?: string;
/**
* If this column is foreign key then this specifies the name for it.
*/
foreignKeyConstraintName?: string;
/**
* Generated column expression.
*/
asExpression?: string;
/**
* Generated column type.
*/
generatedType?: "VIRTUAL" | "STORED";
/**
* Identity column type. Supports only in Postgres 10+.
*/
generatedIdentity?: "ALWAYS" | "BY DEFAULT";
/**
* Return type of HSTORE column.
* Returns value as string or as object.
*/
hstoreType?: "object" | "string";
/**
* Indicates if this column is an array.
* Can be simply set to true or array length can be specified.
* Supported only by postgres.
*/
array?: boolean;
/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
/**
* Spatial Feature Type (Geometry, Point, Polygon, etc.)
*/
spatialFeatureType?: string;
/**
* SRID (Spatial Reference ID (EPSG code))
*/
srid?: number;
}
/**
* Options for spatial columns.
*/
interface SpatialColumnOptions {
/**
* Column type's feature type.
* Geometry, Point, Polygon, etc.
*/
spatialFeatureType?: Geometry["type"];
/**
* Column type's SRID.
* Spatial Reference ID or EPSG code.
*/
srid?: number;
}
/**
* Describes all foreign key options.
*/
interface ForeignKeyOptions {
/**
* Name of the foreign key constraint.
*/
name?: string;
/**
* Database cascade action on delete.
*/
onDelete?: OnDeleteType;
/**
* Database cascade action on update.
*/
onUpdate?: OnUpdateType;
/**
* Indicate if foreign key constraints can be deferred.
*/
deferrable?: DeferrableType;
}
/**
* Describes join column options.
*/
interface JoinColumnOptions {
/**
* Name of the column.
*/
name?: string;
/**
* Name of the column in the entity to which this column is referenced.
*/
referencedColumnName?: string;
/**
* Name of the foreign key constraint.
*/
foreignKeyConstraintName?: string;
}
/**
* Describes all join table with multiple column options.
*/
interface JoinTableMultipleColumnsOptions {
/**
* Name of the table that will be created to store values of the both tables (join table).
* By default is auto generated.
*/
name?: string;
/**
* First column of the join table.
*/
joinColumns?: JoinColumnOptions[];
/**
* Second (inverse) column of the join table.
*/
inverseJoinColumns?: JoinColumnOptions[];
/**
* Database where join table will be created.
* Works only in some databases (like mysql and mssql).
*/
database?: string;
/**
* Schema where join table will be created.
* Works only in some databases (like postgres and mssql).
*/
schema?: string;
/**
* Indicates if schema synchronization is enabled or disabled junction table.
* If it will be set to false then schema sync will and migrations ignores junction table.
* By default schema synchronization is enabled.
*/
readonly synchronize?: boolean;
}
/**
* Describes join table options.
*/
interface JoinTableOptions {
/**
* Name of the table that will be created to store values of the both tables (join table).
* By default is auto generated.
*/
name?: string;
/**
* First column of the join table.
*/
joinColumn?: JoinColumnOptions;
/**
* Second (inverse) column of the join table.
*/
inverseJoinColumn?: JoinColumnOptions;
/**
* Database where join table will be created.
* Works only in some databases (like mysql and mssql).
*/
database?: string;
/**
* Schema where join table will be created.
* Works only in some databases (like postgres and mssql).
*/
schema?: string;
/**
* Indicates if schema synchronization is enabled or disabled junction table.
* If it will be set to false then schema sync will and migrations ignores junction table.
* By default schema synchronization is enabled.
*/
synchronize?: boolean;
}
/**
* Options for columns that can define a length of the column type.
*/
interface ColumnWithLengthOptions {
/**
* Column type's length.
* For example type = "varchar" and length = "100" means ORM will create a column with type varchar(100).
*/
length?: string | number;
}
/**
* Options for numeric column types where user can specify scale and precision.
*/
interface ColumnNumericOptions {
/**
* 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;
/**
* 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;
}
/**
* Column options for enum-typed columns.
*/
interface ColumnEnumOptions {
/**
* Array of possible enumerated values.
*/
enum?: any[] | Object;
/**
* Exact name of enum
*/
enumName?: string;
}
/**
* Column options specific to embedded column.
*/
interface ColumnEmbeddedOptions {
/**
* Embedded column prefix.
* If set to empty string or false, then prefix is not set at all.
*/
prefix?: string | boolean;
/**
* Indicates if this embedded is in array mode.
*
* This option works only in mongodb.
*/
array?: boolean;
}
/**
* Column options for enum-typed columns.
*/
interface ColumnHstoreOptions {
/**
* Return type of HSTORE column.
* Returns value as string or as object.
*/
hstoreType?: string;
}
/**
* Options for columns that can define a length of the column type.
*/
interface ColumnWithWidthOptions {
/**
* 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;
/**
* 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 this column
*/
zerofill?: boolean;
/**
* Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
*/
unsigned?: boolean;
}
/**
* Describes all options for PrimaryGeneratedColumn decorator with numeric generation strategy.
*/
interface PrimaryGeneratedColumnNumericOptions {
/**
* Column type. Must be one of the value from the ColumnTypes class.
*/
type?: PrimaryGeneratedColumnType;
/**
* Column name in the database.
*/
name?: string;
/**
* Column comment. Not supported by all database types.
*/
comment?: string;
/**
* 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;
/**
* Name of the primary key constraint.
*/
primaryKeyConstraintName?: string;
}
/**
* Describes all options for PrimaryGeneratedColumn decorator with numeric uuid strategy.
*/
interface PrimaryGeneratedColumnUUIDOptions {
/**
* Column name in the database.
*/
name?: string;
/**
* Column comment. Not supported by all database types.
*/
comment?: string;
/**
* Name of the primary key constraint.
*/
primaryKeyConstraintName?: string;
}
/**
* Describes all options for PrimaryGeneratedColumn decorator with identity generation strategy.
*/
interface PrimaryGeneratedColumnIdentityOptions {
/**
* Column type. Must be one of the value from the ColumnTypes class.
*/
type?: PrimaryGeneratedColumnType;
/**
* Column name in the database.
*/
name?: string;
/**
* Column comment. Not supported by all database types.
*/
comment?: string;
/**
* Identity column type. Supports only in Postgres 10+.
*/
generatedIdentity?: "ALWAYS" | "BY DEFAULT";
/**
* Name of the primary key constraint.
*/
primaryKeyConstraintName?: string;
}
/**
* Describes all calculated column's options.
*/
interface VirtualColumnOptions {
/**
* Column type. Must be one of the value from the ColumnTypes class.
*/
type?: ColumnType;
/**
* Return type of HSTORE column.
* Returns value as string or as object.
*/
hstoreType?: "object" | "string";
/**
* Query to be used to populate the column data. This query is used when generating the relational db script.
* The query function is called with the current entities alias either defined by the Entity Decorator or automatically
* @See https://typeorm.io/decorator-reference#virtualcolumn for more details.
*/
query: (alias: string) => string;
/**
* Specifies a value transformer(s) that is to be used to unmarshal
* this column when reading from the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
}
/**
* Describes all view column's options.
*/
interface ViewColumnOptions {
/**
* Column name in the database.
*/
name?: string;
/**
* Specifies a value transformer(s) that is to be used to unmarshal
* this column when reading from the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
}
/**
* Describes all index options.
*/
interface IndexOptions {
/**
* Indicates if this composite index must be unique or not.
*/
unique?: boolean;
/**
* The SPATIAL modifier indexes the entire column and does not allow indexed columns to contain NULL values.
* Works only in MySQL and PostgreSQL.
*/
spatial?: boolean;
/**
* The FULLTEXT modifier indexes the entire column and does not allow prefixing.
* Works only in MySQL.
*/
fulltext?: 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.
*/
nullFiltered?: boolean;
/**
* Fulltext parser.
* Works only in MySQL.
*/
parser?: string;
/**
* Index filter condition.
*/
where?: string;
/**
* If true, the index only references documents with the specified field.
* These indexes use less space but behave differently in some situations (particularly sorts).
* This option is only supported for mongodb database.
*/
sparse?: boolean;
/**
* Builds the index in the background so that building an index an does not block other database activities.
* This option is only supported for mongodb database.
*/
background?: boolean;
/**
* Create the index using the CONCURRENTLY modifier
* Works only in postgres.
*/
concurrent?: boolean;
/**
* Specifies a time to live, in seconds.
* This option is only supported for mongodb database.
*/
expireAfterSeconds?: number;
}
/**
* Describes all entity's options.
*/
interface EntityOptions {
/**
* Table name.
* If not specified then naming strategy will generate table name from entity name.
*/
name?: string;
/**
* Specifies a default order by used for queries from this table when no explicit order by is specified.
*/
orderBy?: OrderByCondition | ((object: any) => OrderByCondition | any);
/**
* Table's database engine type (like "InnoDB", "MyISAM", etc).
* It is used only during table creation.
* If you update this value and table is already created, it will not change table's engine type.
* Note that not all databases support this option.
*/
engine?: string;
/**
* Database name. Used in Mysql and Sql Server.
*/
database?: string;
/**
* Schema name. Used in Postgres and Sql Server.
*/
schema?: string;
/**
* Indicates if schema synchronization is enabled or disabled for this entity.
* If it will be set to false then schema sync will and migrations ignore this entity.
* By default schema synchronization is enabled for all entities.
*/
synchronize?: boolean;
/**
* If set to 'true' this option disables Sqlite's default behaviour of secretly creating
* an integer primary key column named 'rowid' on table creation.
* @see https://www.sqlite.org/withoutrowid.html.
*/
withoutRowid?: boolean;
/**
* Table comment. Not supported by all database types.
*/
comment?: string;
}
/**
* Describes all entity view's options.
*/
interface ViewEntityOptions {
/**
* View name.
* If not specified then naming strategy will generate view name from class name.
*/
name?: string;
/**
* View expression.
*/
expression?: string | ((connection: DataSource) => SelectQueryBuilder<any>);
/**
* Database name. Used in Mysql and Sql Server.
*/
database?: string;
/**
* Schema name. Used in Postgres and Sql Server.
*/
schema?: string;
/**
* Indicates if schema synchronization is enabled or disabled for this entity.
* If it will be set to false then schema sync will and migrations ignore this entity.
* By default schema synchronization is enabled for all entities.
*/
synchronize?: boolean;
/**
* Indicates if view should be materialized view.
* It's supported by Postgres and Oracle.
*/
materialized?: boolean;
/**
* View dependencies. In case the view depends on another view it can be listed here
* to ensure correct order of view migrations.
*/
dependsOn?: (Function | string)[];
}
/**
* Describes all unique options.
*/
interface UniqueOptions {
/**
* Indicate if unique constraints can be deferred.
*/
deferrable?: DeferrableType;
}
export type { ColumnCommonOptions, ColumnEmbeddedOptions, ColumnEnumOptions, ColumnHstoreOptions, ColumnNumericOptions, ColumnOptions, ColumnWithLengthOptions, ColumnWithWidthOptions, EntityOptions, ForeignKeyOptions, IndexOptions, JoinColumnOptions, JoinTableMultipleColumnsOptions, JoinTableOptions, PrimaryGeneratedColumnIdentityOptions, PrimaryGeneratedColumnNumericOptions, PrimaryGeneratedColumnUUIDOptions, RelationOptions, SpatialColumnOptions, UniqueOptions, ValueTransformer, ViewColumnOptions, ViewEntityOptions, VirtualColumnOptions };