Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getConnection/getRepository typeorm is deprecated

i get error for import typeOrm

enter image description here

anyone know why my typeorm package is deprecated?

enter image description here

like image 941
Irfan Avatar asked Nov 17 '25 15:11

Irfan


1 Answers

Connection, ConnectionOptions are deprecated, new names to use are: DataSource and DataSourceOptions. To create the same connection you had before use a new syntax: new DataSource({ /*...*/ }).

createConnection(), createConnections() are deprecated, since Connection is called DataSource now, to create a connection and connect to the database simply do:

server.ts

export const appDataSource = new DataSource({
   // ... options
});

const main = async () => {
    console.time('main');
    await appDataSource.initialize();
};

main().catch(err => {
    console.error(err);
    process.exit(1);
});

user.resolver.ts

import { appDataSource } from '@server';
import { User } from '@entity/user.entity';

export class UserResolver {
    userRepo = appDataSource.getRepository(User);
}

changelog: https://github.com/typeorm/typeorm/blob/master/CHANGELOG.md

like image 141
umutyerebakmaz Avatar answered Nov 19 '25 07:11

umutyerebakmaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!