getConnection/getRepository typeorm is deprecated

Viewed 7005

i get error for import typeOrm

enter image description here

anyone know why my typeorm package is deprecated?

enter image description here

5 Answers

What is your current typeorm version? Because there are several deprecations on typeorm@0.3.0 Here is the change logs file for that https://github.com/typeorm/typeorm/blob/master/CHANGELOG.md

getConnection() is deprecated. To have a globally accessible connection, simply export your data source and use it in places you need it:

export const myDataSource = new DataSource({ /*...*/ })
// now you can use myDataSource anywhere in your application

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
});

appDataSource.initialize();

user.resolver.ts

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

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

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

it may be that GetConnect is lagged, clicking on the import may suggest which one to replace, or you need to install the library you intend to use.

Try to reinstall package:

  • yarn remove typeorm
  • yarn add typeorm

Can you show more details?

  • this is PosgreSQL?
  • show the code base of your solution, may be in nest docs
Related