@athenna/database
Version:
The Athenna database handler for SQL/NoSQL.
68 lines (67 loc) • 1.96 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 { Macroable } from '@athenna/common';
import { BaseModel } from '#src/models/BaseModel';
export declare class ModelFactory<M extends BaseModel = any, R = M> extends Macroable {
/**
* The model that will be used to fabricate
* instances from.
*/
private Model;
/**
* The number of models to be created.
*/
private _count;
/**
* Set if the soft delete state is active or not.
*/
private _trashed;
/**
* Set the returning key that this factory will return.
*/
private _returning;
constructor(model: typeof BaseModel);
returning(key: '*'): ModelFactory<M>;
returning<T extends keyof M>(key: T): ModelFactory<M, M[T]>;
/**
* Same as returning method, but return the type of
* the key of the model to avoid using "as any" or
* other kind of stuffs to fix the type in definition
* method.
*
* Only the type is modified for convenience, the real
* return type of this method is still the ModelFactory
* instance.
*/
returningAs<T extends keyof M>(key: T): M[T];
/**
* Set the soft delete state in your model to
* fabricate deleted data.
*/
trashed(): this;
/**
* Remove the soft delete state in your model to
* not fabricate deleted data.
*/
untrashed(): this;
count(number: 1): ModelFactory<M, R>;
count(number: number): ModelFactory<M, R[]>;
/**
* Make models without creating it on database.
*/
make(override?: Partial<M>): Promise<R>;
/**
* Create models creating it on database.
*/
create(override?: Partial<M>): Promise<R>;
/**
* Execute the definition method and return data.
*/
private getDefinition;
}