iagate-querykit
Version:
QueryKit: lightweight TypeScript query toolkit with models, views, triggers, events, scheduler and adapters (better-sqlite3).
50 lines • 1.59 kB
TypeScript
/**
* Função seletora para definir quais relações carregar.
* Permite especificar quais campos de cada relação incluir.
*
* @example
* ```typescript
* // Dados iniciais
* const selector: Selector = (rel) => {
* rel('posts', ['id', 'title', 'content']);
* rel('profile', ['bio', 'avatar']);
* };
*
* // Como usar
* // Passado para attachRelations
*
* // Output: Seletor configurado para carregar posts e profile
* ```
*/
type Selector = (rel: (name: string, select?: string[]) => void) => void;
/**
* Anexa relações a registros de uma tabela baseado em definições de relacionamento.
* Suporta hasMany, belongsTo e manyToMany com carregamento lazy.
*
* @param table - Nome da tabela principal
* @param rows - Array de registros para anexar relações
* @param selector - Função opcional para selecionar relações específicas
* @returns Promise que resolve com registros com relações anexadas
*
* @example
* ```typescript
* // Dados iniciais
* const users = [
* { id: 1, name: 'John' },
* { id: 2, name: 'Jane' }
* ];
*
* // Como usar
* const usersWithRelations = await attachRelations('users', users, (rel) => {
* rel('posts', ['id', 'title']);
* rel('profile');
* });
*
* // Output: Usuários com posts e profile carregados
* // usersWithRelations[0].posts = [{ id: 1, title: 'Post 1' }]
* // usersWithRelations[0].profile = { bio: 'Developer' }
* ```
*/
export declare function attachRelations(table: string, rows: any[], selector?: Selector): Promise<any[]>;
export {};
//# sourceMappingURL=relations-resolver.d.ts.map