[Vapor3][MySQL] Show the error 'DatabaseIdentifier<_>' produces result of type 'DatabaseIdentifier<MySQLDatabase>', but context expects 'DatabaseIdentifier<_>'
[10/21, 2018] |
Cause of the error
Why Xcode shows you an error like below even if you set the DatabaseIdentifier properly.
Member 'mysql' in 'DatabaseIdentifier<>' produces result of type 'DatabaseIdentifier
Causes are
- Something wrong the code inside of closure.
- No code inside of closure yet.
So, if you write code properly inside the closure, the error will be gone.
Patterns with the error.
let result = context.container.withNewConnection(to: .mysql){
conn in
}
let result = context.container.withNewConnection(to: .mysql){
conn in
return 1
}
etc.
Patterns without the error.
let result = context.container.withNewConnection(to: .mysql){
conn in
return conn.raw("select * from talbeA;").all()
}
Xcode might not be able to show the error properly if the code inside the closure is wrong. I spent a lot of time because of this error😠I hope this article helps someone like me.