[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
if (module['hot']) {
module['hot'].accept()
module['hot'].dispose(() => {
app.close()
})
}
Nest version: 5.0.0
TypeORM version: 0.2.5
MySQL version: 2.15.0
For Tooling issues:
- Node version: 8.11.2
- Platform: Mac
Others:
Hi.
I think you should post (at least) your connection & configuration code (call to TypeOrmModule.forRoot, for instance).
Btw, if you're loading entities
as TS files with a global path (e.g. src/**/*.entity.ts
), the default webpack configuration won't allow it / the main script won't run.
There are several issues here:
transpileOnly: true
). Application is still fully reinitialized.import { getConnection } from 'typeorm';
if (module.hot) {
const connection = getConnection();
if (connection.isConnected) {
await connection.close();
}
module.hot.accept();
module.hot.dispose(() => {
app.close();
});
}
See full example here
*.ts
will not work, but you can import entites explicitlyimport { Cat } from './cat/cat.entity';
import { User } from './user/user.entity';
@Module({
imports: [
entities: [
Cat, User
],
}),
],
})
Second option could be webpack require.context feature:
const entityContext = require.context('.', true, /\.entity\.ts$/);
entityContext.keys().forEach(entityContext);
But I did not test it.
Third option is to use ts-node
instead of node (which will parse ts files as well) but it's major hit to performance and using webpack hmr aproach does not make sense at all)
@unlight you can't close connection like that, it will report an error when doing some database operation.
Your errors says "connection is not established", that's why I'm checking flag connection.isConnected
.
Anyway it works for me.
@unlight your code will close the connection at the application startup
I'll extend @nestjs/typeorm
with keepConnection
(or similar one) option in order to avoid reconnecting between successive compilations.
In latest @nestjs/[email protected]
the keepConnectionAlive
option is available. Set it to true in order to reuse the same connection between rebuilds. I'll update the docs soon
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
In latest
@nestjs/[email protected]
thekeepConnectionAlive
option is available. Set it to true in order to reuse the same connection between rebuilds. I'll update the docs soon