artmapper
Version:
Spring Boot clone for Node.js with TypeScript/JavaScript - JPA-like ORM, Lombok decorators, dependency injection, and MySQL support
76 lines • 2.35 kB
TypeScript
import 'reflect-metadata';
import { Pool } from 'mysql2/promise';
import { RelationshipManager } from './RelationshipManager';
export declare class EntityManager {
private pool;
private relationshipManager;
constructor(pool: Pool);
/**
* Persist an entity to the database
* @param entity The entity to persist
* @param fieldsToUpdate Optional array of field names to update (for partial updates)
*/
persist<T>(entity: T, fieldsToUpdate?: string[]): Promise<T>;
/**
* Find an entity by ID
*/
find<T>(entityClass: new () => T, id: any): Promise<T | null>;
/**
* Find all entities
*/
findAll<T>(entityClass: new () => T): Promise<T[]>;
/**
* Remove an entity from the database
*/
remove<T>(entity: T): Promise<void>;
/**
* Execute a custom query
*/
query<T>(sql: string, params?: any[]): Promise<T[]>;
/**
* Execute a custom query and return single result
*/
queryOne<T>(sql: string, params?: any[]): Promise<T | null>;
/**
* Create a query builder
*/
createQueryBuilder(entityClass: Function): QueryBuilder;
/**
* Map database row to entity instance
*/
private mapRowToEntity;
/**
* Load relationships for an entity (EAGER loading)
*/
loadRelationships<T>(entity: T): Promise<T>;
/**
* Get relationship manager for manual relationship loading
*/
getRelationshipManager(): RelationshipManager;
}
/**
* Query Builder for type-safe queries
*/
export declare class QueryBuilder {
private pool;
private entityClass;
private selectClause;
private fromClause;
private whereClauses;
private whereParams;
private orderByClause;
private limitClause;
private joinClauses;
constructor(pool: Pool, entityClass: Function);
select(fields: string): this;
where(condition: string, ...params: any[]): this;
andWhere(condition: string, ...params: any[]): this;
orderBy(field: string, direction?: 'ASC' | 'DESC'): this;
limit(count: number, offset?: number): this;
join(table: string, condition: string): this;
leftJoin(table: string, condition: string): this;
getMany<T>(): Promise<T[]>;
getOne<T>(): Promise<T | null>;
private buildQuery;
}
//# sourceMappingURL=EntityManager.d.ts.map