open-index/open-npm huggingface dataset:
npm package: @introspectivelabs/nestjs-typeorm
Description: Reusable NestJS TypeORM utilities: BaseRepository with pagination and EntityRepository factory
Author: Introspective Labs
Latest version: 0.1.0

# @introspectivelabs/nestjs-typeorm

Reusable NestJS TypeORM utilities: `BaseRepository` with pagination and `EntityRepository` factory.

## Installation

```bash
npm install @introspectivelabs/nestjs-typeorm
```

### Peer Dependencies

- `@nestjs/common` >= 10.0.0
- `@nestjs/typeorm` >= 10.0.0
- `nestjs-typeorm-paginate` >= 4.0.0
- `typeorm` >= 0.3.0

## Usage

### EntityRepository Factory

Create a typed repository class with automatic dependency injection:

```typescript
import { EntityRepository } from "@introspectivelabs/nestjs-typeorm";
import { User } from "./user.entity";

@Injectable()
export class UserRepository extends EntityRepository(User) {}
```

Register it in your module:

```typescript
@Module({
  imports: [TypeOrmModule.forFeature([User])],
  providers: [UserRepository],
  exports: [UserRepository],
})
export class UserModule {}
```

### BaseRepository Methods

All repositories created with `EntityRepository` extend `BaseRepository`, which provides:

```typescript
// Pagination
await repo.paginate(queryBuilder, { limit: 10, page: 1 });
await repo.paginateRaw(queryBuilder, options);
await repo.paginateRawEntities(queryBuilder, options);

// CRUD helpers
await repo.findOneByIdOrFail(id);
await repo.createOne({ name: "New Entity" });
await repo.createMany([{ name: "A" }, { name: "B" }]);
await repo.updateOneById(id, { name: "Updated" });
await repo.deleteOneById(id);
```

Default pagination options: `{ limit: 15, page: 1 }`.

### Multiple DataSources

Pass a connection name to `EntityRepository`:

```typescript
export class AuditRepository extends EntityRepository(AuditLog, "audit-connection") {}
```

## License

Apache-2.0