UNPKG

@athenna/database

Version:

The Athenna database handler for SQL/NoSQL.

59 lines (58 loc) 1.66 kB
/** * @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 { Macroable } from '@athenna/common'; import type { RelationOptions } from '#src/types'; import type { BaseModel } from '#src/models/BaseModel'; import { ModelSchema } from '#src/models/schemas/ModelSchema'; export declare class ModelGenerator<M extends BaseModel = any> extends Macroable { /** * The model that will be generated instances * from. */ private Model; /** * The model schema that will be used to search * for columns and relations. */ private schema; constructor(model: new () => M, schema: ModelSchema<M>); /** * Generate one model instance with relations loaded. */ generateOne(data: any): Promise<M>; /** * Generate models instances with relations loaded. */ generateMany(data: any[]): Promise<M[]>; /** * Instantiate one model using vanilla database data. */ private instantiateOne; /** * Populate one object data in the model instance * using the column dictionary to map keys. */ private populate; /** * Include one relation to one model. */ includeRelation(model: M, relation: RelationOptions): Promise<M>; /** * Include all relations to one model. */ private includeRelations; /** * Include one relation for all models. */ private includeRelationOfAll; /** * Include all relations for all models. */ private includeRelationsOfAll; }