lakutata
Version:
An IoC-based universal application framework.
550 lines (535 loc) • 16.1 kB
TypeScript
import './TypeDef.internal.30.js';
import { SelectQueryBuilder } from './TypeDef.internal.38.js';
import { OrderByCondition } from './TypeDef.internal.74.js';
import { RelationType, OnDeleteType, OnUpdateType, DeferrableType, TableType } from './TypeDef.internal.73.js';
import { DataSource } from './TypeDef.internal.33.js';
import { ColumnType } from './TypeDef.internal.44.js';
import { ForeignKeyOptions, SpatialColumnOptions, ValueTransformer, JoinTableOptions, JoinTableMultipleColumnsOptions, JoinColumnOptions, ColumnOptions } from './TypeDef.internal.68.js';
import { EntityTarget } from './TypeDef.internal.36.js';
interface EntitySchemaIndexOptions {
/**
* Index name.
*/
name?: string;
/**
* Index column names.
*/
columns?: ((object?: any) => any[] | {
[]: number;
}) | string[];
/**
* Indicates if index must sync with database index.
*/
synchronize?: boolean;
/**
* 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;
/**
* Indicates if this 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;
}
interface EntitySchemaColumnForeignKeyOptions extends ForeignKeyOptions {
/**
* Indicates with which entity this relation is made.
*/
target: EntityTarget<any>;
/**
* Inverse side of the relation.
*/
inverseSide?: string;
}
interface EntitySchemaColumnOptions extends SpatialColumnOptions {
/**
* Indicates if this column is a primary column.
*/
primary?: boolean;
/**
* Indicates if this column is of type ObjectId
*/
objectId?: boolean;
/**
* Indicates if this column is a created date column.
*/
createDate?: boolean;
/**
* Indicates if this column is an update date column.
*/
updateDate?: boolean;
/**
* Indicates if this column is a delete date column.
*/
deleteDate?: boolean;
/**
* Indicates if this column is a version column.
*/
version?: boolean;
/**
* Indicates if this column is a treeChildrenCount column.
*/
treeChildrenCount?: boolean;
/**
* Indicates if this column is a treeLevel column.
*/
treeLevel?: boolean;
/**
* 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. 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.
*/
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;
/**
* Specifies if this column will use AUTO_INCREMENT or not (e.g. generated number).
*/
generated?: true | "increment" | "uuid" | "rowid";
/**
* Specifies if column's value must be unique or not.
*/
unique?: boolean;
/**
* Extra column definition. Should be used only in emergency situations. Note that if you'll use this property
* auto schema generation will not work properly anymore. Avoid using it.
*/
columnDefinition?: string;
/**
* Column comment.
*/
comment?: string;
/**
* Default database value.
*/
default?: any;
/**
* ON UPDATE trigger. Works only for MySQL.
*/
onUpdate?: 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;
/**
* 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;
/**
* 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?: any[] | Object;
/**
* Exact name of enum
*/
enumName?: string;
/**
* Generated column expression.
*/
asExpression?: string;
/**
* Generated column type.
*/
generatedType?: "VIRTUAL" | "STORED";
/**
* 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[];
/**
* Name of the primary key constraint.
*/
primaryKeyConstraintName?: string;
/**
* Foreign key options of this column.
*/
foreignKey?: EntitySchemaColumnForeignKeyOptions;
}
interface EntitySchemaRelationOptions {
/**
* Indicates with which entity this relation is made.
*/
target: EntityTarget<any>;
/**
* Type of relation. Can be one of the value of the RelationTypes class.
*/
type: RelationType;
/**
* Inverse side of the relation.
*/
inverseSide?: string;
/**
* Indicates if this relation will be lazily loaded.
*/
lazy?: boolean;
/**
* Indicates if this relation will be eagerly loaded.
*/
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;
/**
* Indicates if this relation will be a primary key.
* Can be used only for many-to-one and owner one-to-one relations.
*/
primary?: boolean;
/**
* 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;
/**
* Join table options of this column. If set to true then it simply means that it has a join table.
*/
joinTable?: boolean | JoinTableOptions | JoinTableMultipleColumnsOptions;
/**
* Join column options of this column. If set to true then it simply means that it has a join column.
*/
joinColumn?: boolean | JoinColumnOptions | JoinColumnOptions[];
/**
* Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.
*/
treeParent?: boolean;
/**
* Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.
*/
treeChildren?: boolean;
/**
* If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.
* This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.
*/
cascade?: boolean | ("insert" | "update" | "remove" | "soft-remove" | "recover")[];
/**
* Default database value.
*/
default?: any;
/**
* 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;
/**
* 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.
* skip will keep the relation intact. Removal of related item is only possible through its own repo.
*/
orphanedRowAction?: "nullify" | "delete" | "soft-delete" | "disable";
}
interface EntitySchemaUniqueOptions {
/**
* Unique constraint name.
*/
name?: string;
/**
* Unique column names.
*/
columns?: ((object?: any) => any[] | {
[]: number;
}) | string[];
/**
* Indicate if unique constraints can be deferred.
*/
deferrable?: DeferrableType;
}
interface EntitySchemaCheckOptions {
/**
* Check constraint name.
*/
name?: string;
/**
* Check expression.
*/
expression: string;
}
interface EntitySchemaExclusionOptions {
/**
* Exclusion constraint name.
*/
name?: string;
/**
* Exclusion expression.
*/
expression: string;
}
interface EntitySchemaInheritanceOptions {
/**
* Inheritance pattern.
*/
pattern?: "STI";
/**
* Inheritance discriminator column.
*/
column?: string | ColumnOptions;
}
interface EntitySchemaRelationIdOptions {
/**
* Name of relation.
*/
relationName: string;
/**
* Alias of the joined (destination) table.
*/
alias?: string;
/**
* Extra condition applied to "ON" section of join.
*/
queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;
}
interface EntitySchemaForeignKeyOptions extends ForeignKeyOptions {
/**
* Indicates with which entity this relation is made.
*/
target: EntityTarget<any>;
/**
* Column names which included by this foreign key.
*/
columnNames: string[];
/**
* Column names which included by this foreign key.
*/
referencedColumnNames: string[];
}
/**
* Interface for entity metadata mappings stored inside "schemas" instead of models decorated by decorators.
*/
declare class EntitySchemaOptions<T> {
/**
* Target bind to this entity schema. Optional.
*/
target?: Function;
/**
* Entity name.
*/
name: string;
/**
* Table name.
*/
tableName?: string;
/**
* Database name. Used in MySql and Sql Server.
*/
database?: string;
/**
* Schema name. Used in Postgres and Sql Server.
*/
schema?: string;
/**
* Table type.
*/
type?: TableType;
/**
* Specifies a property name by which queries will perform ordering by default when fetching rows.
*/
orderBy?: OrderByCondition;
/**
* Entity column's options.
*/
columns: {
[]?: EntitySchemaColumnOptions;
};
/**
* Entity relation's options.
*/
relations?: {
[]?: EntitySchemaRelationOptions;
};
/**
* Entity relation id options.
*/
relationIds?: {
[]?: EntitySchemaRelationIdOptions;
};
/**
* Entity indices options.
*/
indices?: EntitySchemaIndexOptions[];
/**
* Entity foreign keys options.
*/
foreignKeys?: EntitySchemaForeignKeyOptions[];
/**
* Entity uniques options.
*/
uniques?: EntitySchemaUniqueOptions[];
/**
* Entity check options.
*/
checks?: EntitySchemaCheckOptions[];
/**
* Entity exclusion options.
*/
exclusions?: EntitySchemaExclusionOptions[];
/**
* Embedded Entities options
*/
embeddeds?: {
[]: EntitySchemaEmbeddedColumnOptions;
};
/**
* 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;
/**
* View expression.
*/
expression?: string | ((connection: DataSource) => SelectQueryBuilder<any>);
/**
* Inheritance options.
*/
inheritance?: EntitySchemaInheritanceOptions;
/**
* Custom discriminator value for Single Table Inheritance.
*/
discriminatorValue?: string;
}
/**
* Interface for entity metadata mappings stored inside "schemas" instead of models decorated by decorators.
*/
declare class EntitySchema<T = any> {
options: EntitySchemaOptions<T>;
readonly "@instanceof": symbol;
constructor(options: EntitySchemaOptions<T>);
}
declare class EntitySchemaEmbeddedColumnOptions {
/**
* Schema of embedded entity
*/
schema: EntitySchema;
/**
* 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;
}
export { EntitySchema, EntitySchemaEmbeddedColumnOptions, EntitySchemaOptions };
export type { EntitySchemaColumnOptions, EntitySchemaIndexOptions, EntitySchemaRelationOptions };