@athenna/database
Version:
The Athenna database handler for SQL/NoSQL.
178 lines (177 loc) • 6.02 kB
TypeScript
/**
* @athenna/database
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import type { ColumnOptions, ModelColumns, ModelRelations, RelationOptions } from '#src/types';
import type { BaseModel } from '#src/models/BaseModel';
import { Macroable } from '@athenna/common';
import type { ModelQueryBuilder } from '#src/models/builders/ModelQueryBuilder';
export declare class ModelSchema<M extends BaseModel = any> extends Macroable {
/**
* Save the columns defined by @Column annotation.
*/
columns: ColumnOptions[];
/**
* Save the relations defined by \@HasOne, \@BelongsTo,
* \@HasMany and \@ManyToMany annotations.
*/
relations: RelationOptions[];
/**
* The model class that is going to be used
* to craft the schema.
*/
private Model;
constructor(model: any);
/**
* Sync the database creating migrations
* or schemas in the database connection.
*/
sync(): Promise<void>;
/**
* Get the model name set for the schema.
*/
getModelName(): string;
/**
* Get the model table set for the schema.
*/
getModelTable(): string;
/**
* Get the model driver name.
*/
getModelDriverName(): any;
/**
* Get the model driver.
*/
getModelDriver(): import("../../database/drivers/MongoDriver.js").MongoDriver | import("../../database/drivers/MySqlDriver.js").MySqlDriver | import("../../database/drivers/SqliteDriver.js").SqliteDriver | import("../../database/drivers/PostgresDriver.js").PostgresDriver | typeof import("../../database/drivers/FakeDriver.js").FakeDriver;
/**
* Get the model connection name.
*/
getModelConnection(): string;
/**
* Get the column options of the main primary key.
*/
getMainPrimaryKey(): ColumnOptions;
/**
* Get the main primary key column name.
*/
getMainPrimaryKeyName(): string;
/**
* Get the main primary key property.
*/
getMainPrimaryKeyProperty(): string;
/**
* Convert an object using properties to database use
* column names.
*/
propertiesToColumnNames(data: Partial<M> | ModelColumns<M>, options?: {
attributes?: Record<string, any>;
cleanPersist?: boolean;
}): {};
/**
* Get the column options where column has isCreateDate
* as true.
*/
getCreatedAtColumn(): ColumnOptions;
/**
* Get the column options where column has isUpdateDate
* as true.
*/
getUpdatedAtColumn(): ColumnOptions;
/**
* Get the column options where column has isDeleteDate
* as true.
*/
getDeletedAtColumn(): ColumnOptions;
/**
* Get all column properties as an array of string.
*/
getAllColumnProperties(): string[];
/**
* Get all column names as an array of string.
*/
getAllColumnNames(): string[];
/**
* Get all columns where unique option is true.
*/
getAllUniqueColumns(): ColumnOptions[];
/**
* Get all columns where hidden option is true.
*/
getAllHiddenColumns(): ColumnOptions[];
/**
* Get all columns where nullable option is false.
*/
getAllNotNullableColumns(): ColumnOptions[];
/**
* Validate that model has createdAt and updatedAt
* column defined.
*/
hasTimestamps(): boolean;
/**
* Get the column options by the column database name.
*/
getColumnByName(column: string | ModelColumns<M>): ColumnOptions;
/**
* Get the column options by the column database name.
*
* If property cannot be found, the column name will be used.
*/
getPropertyByColumnName(column: string | ModelColumns<M>): string;
/**
* Get all the properties names by an array of column database names.
*
* If property cannot be found, the column name will be used.
*/
getPropertiesByColumnNames(columns: string[] | ModelColumns<M>[]): string[];
/**
* Get the column options by the model class property.
*/
getColumnByProperty(property: string | ModelColumns<M>): ColumnOptions;
/**
* Get the column name by the model class property.
*
* If the column name cannot be found, the property will be used.
*/
getColumnNameByProperty(property: string | ModelColumns<M>): string;
/**
* Get all the columns names by an array of model class properties.
*
* If the column name cannot be found, the property will be used.
*/
getColumnNamesByProperties(properties: string[] | ModelColumns<M>[]): string[];
/**
* Get the relation by the class property name.
*/
getRelationByProperty(property: string | ModelColumns<M>): RelationOptions;
/**
* Relation options used only when eager-loading related rows (`with()` /
* {@link ModelSchema.includeRelation includeRelation}). Constraints from
* `whereHas()` are not included here; use `with()` when the response must
* contain related models.
*/
getIncludedRelations(): RelationOptions[];
/**
* Return the relation properties.
*/
getRelationProperties(): string[];
/**
* Include a relation by setting the isIncluded
* option to true.
*/
includeRelation(property: string | ModelRelations<M>, closure?: (query: ModelQueryBuilder) => any): RelationOptions;
/**
* Marks relation metadata for a `whereHas()` constraint (stores closure).
* Does not eager-load related rows; only {@link ModelSchema.includeRelation}
* participates in {@link ModelSchema.getIncludedRelations eager loading}.
*/
includeWhereHasRelation(property: string | ModelRelations<M>, closure?: (query: ModelQueryBuilder) => any): RelationOptions;
/**
* Created nested relationships closure to
* load relationship's relationships
*/
private createdNestedRelationClosure;
}