adonis-odm
Version:
A comprehensive MongoDB ODM for AdonisJS with Lucid-style API, type-safe relationships, embedded documents, and transaction support
58 lines • 2.89 kB
TypeScript
import { ObjectId, Document } from 'mongodb';
import { ModelQueryBuilder } from '../query_builder/model_query_builder.js';
import { ModelOperationOptions } from '../types/index.js';
import type { CreateAttributes } from '../types/embedded.js';
import type { BaseModel } from './base_model.js';
/**
* StaticQueryMethods - Handles all static query methods for BaseModel
*
* This class encapsulates all the static methods for querying and creating
* model instances like find, create, all, etc.
*/
export declare class StaticQueryMethods {
/**
* Create a new query builder instance with type-safe relationship loading
*/
static query<T extends BaseModel = BaseModel>(_modelClass: typeof BaseModel & (new (...args: any[]) => T), _options?: ModelOperationOptions): ModelQueryBuilder<Document, T>;
/**
* Find a document by its ID
*/
static find<T extends BaseModel = BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T), id: string | ObjectId, options?: ModelOperationOptions): Promise<T | null>;
/**
* Find a document by its ID or throw an exception
*/
static findOrFail<T extends BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T), id: string | ObjectId, options?: ModelOperationOptions): Promise<T>;
/**
* Find a document by a specific field
*/
static findBy<T extends BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T), field: string, value: any): Promise<T | null>;
/**
* Find a document by a specific field or throw an exception
*/
static findByOrFail<T extends BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T), field: string, value: any): Promise<T>;
/**
* Get the first document
*/
static first<T extends BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T)): Promise<T | null>;
/**
* Get the first document or throw an exception
*/
static firstOrFail<T extends BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T)): Promise<T>;
/**
* Get all documents
*/
static all<T extends BaseModel>(modelClass: typeof BaseModel & (new (...args: any[]) => T)): Promise<T[]>;
/**
* Create a new document
*/
static create<T extends BaseModel>(modelClass: new (...args: any[]) => T, attributes: CreateAttributes<T>, options?: ModelOperationOptions): Promise<T>;
/**
* Create multiple documents
*/
static createMany<T extends BaseModel>(modelClass: new (...args: any[]) => T, attributesArray: CreateAttributes<T>[]): Promise<T[]>;
/**
* Update or create a document
*/
static updateOrCreate<T extends BaseModel>(modelClass: new (...args: any[]) => T, searchPayload: CreateAttributes<T>, persistencePayload: CreateAttributes<T>): Promise<T>;
}
//# sourceMappingURL=static_query_methods.d.ts.map