You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the Fluent as a library independently of vapor, and trying to connect to database using the following simple code:
// Assume that the 'databases', 'logger', and 'eventloop' objects are initialized correctly.
// The connectionString has a wrong set of credentials, but forms a valid postgres connection string.
do {
try databases.use(.postgres(url: connectionString), as: .psql)
database = databases.database(.psql, logger: logger, on: databases.eventLoopGroup.next())
} catch {
throw error
}
Now, in case of correct credentials, the database connects without any issues. On the other hand, if the database credentials are wrong, the databases.use does not throw any error.
For now, I have found a temporary workaround as follows:
do {
try databases.use(.postgres(url: connectionString), as: .psql)
database = databases.database(.psql, logger: logger, on: databases.eventLoopGroup.next())
// Note: Fluent does not throw error with wrong credentials.
// Temporary workaround.
guard let postgres = database as? PostgresDatabase else {
//Throw some error.
}
_ = try postgres.simpleQuery("SELECT 1").wait()
}
catch {
throw error
}
Could you please correct the fluent API to test connection in the use call, and throw error if the database is not being able to connect?
The text was updated successfully, but these errors were encountered:
I'm using the Fluent as a library independently of vapor, and trying to connect to database using the following simple code:
Now, in case of correct credentials, the database connects without any issues. On the other hand, if the database credentials are wrong, the
databases.use
does not throw any error.For now, I have found a temporary workaround as follows:
Could you please correct the fluent API to test connection in the
use
call, and throw error if the database is not being able to connect?The text was updated successfully, but these errors were encountered: