@aequum/typeorm
v0.27.15
Published
aequum TypeORM tools for repository, pagination, CRUD/CRUDL, configs and utils
Maintainers
Readme
aequum TypeORM tools
A collection of tools which includes:
- Extensible repositories, one with pagination support
- Pagination via
typeorm-paginate - CRUD/CRUDL services via
@aequum/crudl - Duplicate exception handling via
@aequum/exceptions
Components
Repositories
NOTE: For use in NestJS applications see the Repositories on NestJS applications section.
TypeORMRepository: For now just extends the built-in repository from TypeORM, but anyway is recommended to use it for future extensions.TypeORMPaginatedRepository: Extends fromTypeORMRepositoryto provide pagination withpaginatedFindByandpaginateQueryBuildermethods.
Services:
BaseCRUDLTypeORMService: Base CRUDL service implementation for TypeORM (*).BaseCRUDLTypeORMPaginatedService: Extends fromBaseCRUDLTypeORMServiceto provide pagination support (*).
Utils:
duplicateEntryExceptionOrError: Check if the provided error is a duplicate entry error and return aDuplicateEntryException(**) or returns the original error.isDuplicateError: Check if the provided error is a TypeORM duplicate entry error.URIToDataSourceOptions: Converts an URI,{engine}://{host}:{port}/{database}/{schema)?option=value&option2=valuestring toDataSourceOptionsobject.
(*) See @aequum/crudl for more information about CRUDL services.
(**): See @aequum/exceptions for more information about exceptions.
Indications
Repositories on NestJS applications
Repositories must be used in a different way in NestJS applications.
For the repository you must use InjectDataSource() decorator to inject the TypeORM DataSource instance.
@Injectable()
export class UserRepository extends TypeORMPaginatedRepository<User> {
constructor(@InjectDataSource() dataSource: DataSource) {
super(User, dataSource)
}
}And in the module you must provide the repository as a provider:
@Module({
imports: [ TypeOrmModule.forFeature([ User, UserRefreshToken ]) ],
providers: [ UsersService, UserRepository ],
controllers: [ UsersController ],
exports: [ UsersService ],
})
export class UsersModule {}