Comments (13)
See that name
:
https://github.com/nestjs/typeorm/blob/master/lib/interfaces/typeorm-options.interface.ts
should be passed at the same level as useFactory
in case of the multiple connections.
TypeOrmModule.forRootAsync({
name: 'gameServerMainConnection',
useFactory: (config: ConfigService) => ({
...
type: 'mysql',
host: '127.0.0.1',
}),
})
from typeorm.
still not working! can't inject relative entity to feature module. @kamilmysliwiec
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => config.typeorm[0] as any,
inject: [ConfigService],
}),
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => ({
name: 'gameServerMainConnection',
type: 'mysql',
host: '127.0.0.1',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
entities: [SystemSettingEntity],
logging: true,
dateStrings: true,
timezone: '+08:00',
supportBigNumbers: true,
bigNumberStrings: false,
}),
inject: [ConfigService],
}),
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => config.typeorm[2] as any,
inject: [ConfigService],
}),
],
exports: [TypeOrmModule],
})
export class DatabaseModule {}
@Module({
imports: [
TypeOrmModule.forFeature([SystemSettingEntity], 'gameServerMainConnection'),
],
controllers: [SystemSettingController],
providers: [SystemSettingService],
})
export class SystemSettingModule {}
[Nest] 26092 - 2018-9-20 17:12:28 [ExceptionHandler] Nest can't resolve dependencies of the SystemSettingEntityRepository (?). Please make sure that the argument at index [0] is available in the current context. +5ms
Error: Nest can't resolve dependencies of the SystemSettingEntityRepository (?). Please make sure that the argument at index [0] is available in the current context.
at Injector.lookupComponentInExports (D:\Projects\game-platform\game-management\game-management-server\node_modules\@nestjs\core\injector\injector.js:146:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:746:11)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
1: node::DecodeWrite
2: node::DecodeWrite
3: v8::internal::interpreter::BytecodeDecoder::Decode
4: v8::internal::RegExpImpl::Exec
5: v8::internal::RegExpImpl::Exec
6: v8::internal::RegExpImpl::Exec
7: 0000000277904281
from typeorm.
@chriscarpenter12 The second example is right. But I don't understand why you return Promise from ConfigService
. In the get
method you can return string
and I think it is better. Btw, It is your decision and I don't know your project specification. If you have a Promises then you can use async
function.
TypeOrmModule.forRootAsync({
useFactory: async (config: ConfigService) => ({
name: await config.get('some.key.here'),
...other keys
}),
inject: [ConfigService],
}),
from typeorm.
I have minim repro of the name issue outside of the useFactory. it causes and error if I have t ORM connections.
#156 .
from typeorm.
The documentation seems to be wrong as the result of useFactory
is ignored if there is a config named default.
from typeorm.
Thanks for reporting. Fixed in 5.2.2!
from typeorm.
Maybe name
property shall be exclude from TypeOrmModuleOptions
returned by useFactory
Oh no, my connection name
is provided by ConfigService
. How to do this?
from typeorm.
This threw me off too. I was trying to pass the name
key with the result of the useFactory
as I was pulling all the variables from my ConfigService
.
from typeorm.
@Diluka @chriscarpenter12 Sorry, but was it the problem? Me is also passing connection name
from config. All is working fine.
from typeorm.
I don't use name
or ormconfig
anymore. I use ConfigService
to provide all the options.
from typeorm.
@vgladimir Can you show us how you are using ConfigService
for the name key?
I could be wrong, but I couldn't get it to work with ConfigService
either as name is outside the injection of ConfigService
in the useFactory
.
TypeOrmModule.forRootAsync({
name: ConfigService.get('some.key.here'), // <-- Config is inaccessible here
useFactory: (config: ConfigService) => config.typeorm[2] as any,
inject: [ConfigService],
}),
Hence we were trying to erroneously pass name with the config in useFactory
.
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => ({
name: config.get('some.key.here'),
...other keys
}),
inject: [ConfigService],
}),
The name is a string and we can't return a promise from the ConfigService here.
It also doesn't help the docs of nestjs-config
reference passing the name key in the config. Which is where I initially had it too.
from typeorm.
@vgladimir I don't disagree about the use of async/await, but my point was that if you try to use the name
key in the useFactory
response it doesn't work. As @kamilmysliwiec said it needed to be outside of useFactory
.
from typeorm.
this is also the case when you do useClass => (....)... the name property which you would return in the useClass is omitted. Instead the name property must be defined next to the useClass Property.
from typeorm.
Related Issues (20)
- add nestjs v9 as a peer dependency of `@nestjs/typeorm` v8 HOT 1
- Nest could not find DataSource element HOT 3
- Result of query with comment is inconsistent and random HOT 20
- TypeOrmModule.forRoot() report errors: ConnectionNotFoundError: Connection "default" was not found. HOT 4
- '"typeorm"' has no exported member named 'InjectRepository'. Did you mean 'getRepository'? HOT 3
- setting synchronize to true gives me a typeorm error HOT 1
- When a custom converter is used on a column, migration fails.(nestjs+typeorm) HOT 1
- Testing mocker issues HOT 1
- Option to not initialize DataSource in createDataSourceFactory HOT 6
- Many to many relation is finding a column that doesn't exists HOT 1
- Polymorphic association #12750 HOT 1
- createTypeOrmProviders should inject EntityManager instead of Connection HOT 1
- Bring back keepConnectionAlive HOT 1
- auto db connection close problem When Execute Graceful shtudown with pm2 HOT 1
- Every migration:generate creates DROP/CREATES constraints and keys HOT 1
- Inject ConfigService into an Entity or Subscriber HOT 4
- Nestjs warns about "TypeOrmModule" taking a long time to serialize HOT 8
- TypeOrmModule makes @Request() unusable HOT 1
- When connectionstring param used, Hostname and database name are not correctly extracted HOT 2
- perhaps Typeorm module didn't passing request response to controller HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm.