数据库连接

import { createConnection } from 'typeorm';

export const MySqlProviders = [
  {
    provide: 'DATABASE_CONNECTION',
    useFactory: async () => await createConnection({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'test',
      entities: [
          __dirname + '/../**/*.entity{.ts,.js}',
      ],
      synchronize: true, //不应在生产中使用设置- 否则您可能会丢失生产数据。
    }),
  },
];

最后更新于