-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support the latest version of typeorm (v0.3.x) #107
Comments
Just made a simple test that showed it's not working because no connection could be found. Looking forward to the update. Thank you! |
any progress? |
since the |
Hey, are there any updates on this? |
Hey, are there any updates on this? |
A possible solution I found was to add to the import { Inject } from '@nestjs/common'
import { DataSource } from 'typeorm'
import { Options, wrapInTransaction } from './wrapInTransaction'
/**
* Used to declare a Transaction operation. In order to use it, you must use {@link BaseRepository} custom repository in order to use the Transactional decorator
* @param connectionName - the typeorm connection name. 'default' by default
* @param propagation - The transaction propagation type. see {@link Propagation}
* @param isolationLevel - The transaction isolation level. see {@link IsolationLevel}
*/
export function Transactional(options?: Options): MethodDecorator {
return (target: any, methodName: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {
Inject(DataSource)(target, '__data_source_key__')
const originalMethod = descriptor.value
descriptor.value = wrapInTransaction(originalMethod, { ...options, name: methodName })
Reflect.getMetadataKeys(originalMethod).forEach((previousMetadataKey) => {
const previousMetadata = Reflect.getMetadata(previousMetadataKey, originalMethod)
Reflect.defineMetadata(previousMetadataKey, previousMetadata, descriptor.value)
})
Object.defineProperty(descriptor.value, 'name', { value: originalMethod.name, writable: false })
}
} Then in the However, after doing this only the I'll keep working on this and try to get a PR but maybe this will help someone else figure it out faster. EDIT: If you want to try it out:
use in your package.json |
this works for me. |
I can add to your solution how not to use BaseRepository
and inside code const repo = dataSource.getRepository(UserEntity); |
Is this why "ERROR [ExceptionHandler] Class constructor repository cannot be invoked without 'new'" occurs when using BaseRepository in "[email protected]"? my version is this so, i use CustomRepository on entity.ts like this. at that time this Error occur. export class UserRepository extends Repository {} i already tried to change my tsconfig.json file's compilerOptions but it doesn't work. 🥲 |
Any updates ? |
The above code from @jczacharia works for me, with one addition (No need to extend the base repo from this lib this way): |
Hi guys, thanks a lot to the author for such a great library. But I'm really sorry that the lib hasn't support last TypeORM changes. I needed this library functionality for my new project but with support of newer versions of TypeORM, so I made a fork of this library and did necessary changes and improvements. I also made a package for easy use in my project. If it helps anyone, you can take a look: https://github.com/Aliheym/typeorm-transactional |
Hey @odavid, @Aliheym's solution still keeps the original library design but creates a breaking change, rather than trying to keep two libraries, why not @Aliheym create a merge in this library with your modifications? Also, maybe you can share the maintainer responsibilities so that it doesn't overwhelm you too much, what do you think? |
It will be cool. |
The TLDR (am I getting this right?): This npm package is no longer being updated (per the latest PR's comment), but there is a forked npm package that is updated: https://www.npmjs.com/package/typeorm-transactional |
even tho the peer dep semver range allows the usage of
typeorm@^0.3.0
, maybe few deprecations & drops on the latest version of typeorm could break[email protected]
typeorm-transactional-cls-hooked/package.json
Lines 63 to 65 in c16e19f
Please, read this when you have time: https://github.com/typeorm/typeorm/releases/tag/0.3.0
And close this Issue when you confirm that we can use your package with the latest version of typeorm. I can't find this out by myself yet.The text was updated successfully, but these errors were encountered: