Error: "getRepository is deprecated on version 0.3.0 and up" can be resolved by making the following change in "main.ts" file: const sessionRepository = app.get(DataSource).getRepository(SessionEntity); Here, "DataSource" needs to be imported from typeorm package :)
SessionsEntity worked perfectly when i did it like so: @Column({ type: 'text' }) json: string; @DeleteDateColumn({ type: 'timestamp', nullable: true }) destroyedAt?: Date; another masterful lesson from AnsonTheDev! thanks so much for this series
While Anson was writing the code with provide and useClass, I was not following this way so when I tried the code without Inject, it didn't work and I was very surprised. Can someone explain please?
Hi, i just faced the same problem. First, i use @freshgiammi/connect-typeorm instead of the one in the video to avoid typeorm dependancies problems.. After that, in the app.module.ts, i change the constructor of the AppModule class and create a method to return Datasource: export class AppModule { constructor(private dataSource: DataSource) {} getDataSource() { return this.dataSource; } } Now in the main.ts file, i add: const sessionRepository = app .get(AppModule) .getDataSource() .getRepository(SessionEntity); In the app.use for the sessions settings , i put: store: new TypeormStore({ cleanupLimit: 2, limitSubquery: false, ttl: 86400, }).connect(sessionRepository) And it seems to work.. I don't really know if this is a good way to do it but it's a patch waiting for Anson answer :p
Hi! I solved it that way: in your app module you define the datasource in your imports array: TypeOrmModule.forRoot({ type: 'postgres', host: process.env.POSTGRES_HOST, port: +process.env.POSTGRES_PORT, username: process.env.POSTGRES_USER, password: process.env.POSTGRES_PASSWORD, database: process.env.POSTGRES_DATABASE, autoLoadEntities: true, logging: false, // entities:[ // 'dist/**/*.entity.js' // ], synchronize: true, migrations: [ 'dist/database/migrations/*.js' ] }), then you can inject the datasource with app.get into your main.ts: const sessionRepository = app.get(DataSource).getRepository(Session) (note, in my case it is "Session" not "SessionEntity" but it's the same model behind)
import {ISession} from 'connect-typeorm' import { Column, Index, PrimaryColumn,Entity, DeleteDateColumn} from 'typeorm' @Entity('sessions') export class SessionEntity implements ISession{ @Index() @Column('bigint') expiredAt= Date.now() @PrimaryColumn('varchar', {length:255}) id='' @Column('text') json: string='' @DeleteDateColumn() destroyedAt?: Date; } now the ISession need @DeleteDateColumn. what should i fill it? only Date?
Error: "getRepository is deprecated on version 0.3.0 and up" can be resolved by making the following change in "main.ts" file:
const sessionRepository = app.get(DataSource).getRepository(SessionEntity);
Here, "DataSource" needs to be imported from typeorm package :)
Thought you were just a life saver. then i saw the deathnote profile 💥 you're on GodMode
Thx man!
I was looking for this solution for the past 2 days. Thanks a lot
Thx!
I've been having this issue for some hours now and now i stumbled on this fix. Thanks man
SessionsEntity worked perfectly when i did it like so:
@Column({ type: 'text' })
json: string;
@DeleteDateColumn({ type: 'timestamp', nullable: true })
destroyedAt?: Date;
another masterful lesson from AnsonTheDev! thanks so much for this series
Great job!
I've started learning NestJs and this is so helpful.
For the cleanupLimit, I was able to fix it by setting limitSubquery to false
Dang bro watching you after so long time still same hype
Great video !! Can you make a video on how we get the session data directly from the memory store.
Can we 'renew' or give the user a new session when their old session expires without asking them to login.
I wanna ask something, why we need to @Inject service on each controller? is it problem just instance the service without inject it?
While Anson was writing the code with provide and useClass, I was not following this way so when I tried the code without Inject, it didn't work and I was very surprised. Can someone explain please?
@@bugraotken I have the code working without inject, its just another way of doing dependency injections.
i found an error getRepository is deprecated on version 0.3.0 and up
Hi, i just faced the same problem.
First, i use @freshgiammi/connect-typeorm instead of the one in the video to avoid typeorm dependancies problems..
After that, in the app.module.ts, i change the constructor of the AppModule class and create a method to return Datasource:
export class AppModule {
constructor(private dataSource: DataSource) {}
getDataSource() {
return this.dataSource;
}
}
Now in the main.ts file, i add:
const sessionRepository = app
.get(AppModule)
.getDataSource()
.getRepository(SessionEntity);
In the app.use for the sessions settings , i put:
store: new TypeormStore({
cleanupLimit: 2,
limitSubquery: false,
ttl: 86400,
}).connect(sessionRepository)
And it seems to work.. I don't really know if this is a good way to do it but it's a patch waiting for Anson answer :p
@@b2omker thank you so much for sharing this idea it helps a lot...yeah waiting for Anson's answer too...
Hi! Can you explain in a video why getRepository is deprecated and how is the best way to solve it
Hi!
I solved it that way:
in your app module you define the datasource in your imports array:
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.POSTGRES_HOST,
port: +process.env.POSTGRES_PORT,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DATABASE,
autoLoadEntities: true,
logging: false,
// entities:[
// 'dist/**/*.entity.js'
// ],
synchronize: true,
migrations: [
'dist/database/migrations/*.js'
]
}),
then you can inject the datasource with app.get into your main.ts:
const sessionRepository = app.get(DataSource).getRepository(Session)
(note, in my case it is "Session" not "SessionEntity" but it's the same model behind)
thank you so much
i confused see this video playlist
import {ISession} from 'connect-typeorm'
import { Column, Index, PrimaryColumn,Entity, DeleteDateColumn} from 'typeorm'
@Entity('sessions')
export class SessionEntity implements ISession{
@Index()
@Column('bigint')
expiredAt= Date.now()
@PrimaryColumn('varchar', {length:255})
id=''
@Column('text')
json: string=''
@DeleteDateColumn()
destroyedAt?: Date;
}
now the ISession need @DeleteDateColumn. what should i fill it? only Date?
👍