drogonframework / drogonframework/drogon

Drogon does not load the database connection configuration from config.json

Open
#2,368 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 13h
Merged PRs (30d)
14

Description

Hello! Drogon does not accept the connection described in config.json. I tried MySQL, sqlite3

`test_drogon: /home/insomnia/Projects/test_drogon/drogon/lib/src/DbClientManager.h:46: drogon::orm::DbClientPtr drogon::orm::DbClientManager::getDbClient(const std::string&): Assertion `dbClientsMap_.find(name) != dbClientsMap_.end()' failed.`

`// Set HTTP listener address and port
drogon::app().addListener("0.0.0.0", 5555);

// drogon::app().createDbClient(
// "mysql", "127.0.0.1", 3306, "ariadne_thread",
// "drogon_user", "RT_s20$146Zs%k", 1, "", "mk", false, "", -1, false);

// Load config file
drogon::app().loadConfigFile("../config.json");
drogon::orm::DbClientPtr db = drogon::app().getDbClient("default");
// drogon::app().loadConfigFile("../config.yaml");
// Run HTTP framework,the method will block in the internal event loop

drogon::app().run();
return 0;`

config.json

{

"db_clients":
[
{
//name: Name of the client,'default' by default
"name": "default",
//rdbms: Server type, postgresql, mysql or sqlite3, "postgresql" by default
"rdbms": "sqlite3",
//filename: Sqlite3 db file name
"filename":"klines.db",
//host: Server address,localhost by default
//"host": "127.0.0.1",
//port: Server port, 5432 by default
//"port": 3306,
//dbname: Database name
//"dbname": "ariadne_thread",
//user: 'postgres' by default
//"user": "drogon_user",
//passwd: '' by default
//"passwd": "RT_s20$146Zs%k",
//is_fast: false by default, if it is true, the client is faster but user can't call
//any synchronous interface of it.
"is_fast": false,
//client_encoding: The character set used by the client. it is empty string by default which
//means use the default character set.
//"client_encoding": "",
//number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
//connections per IO thread, otherwise it is the total number of all connections.
"number_of_connections": 1,
//timeout: -1.0 by default, in seconds, the timeout for executing a SQL query.
//zero or negative value means no timeout.
"timeout": -1.0,
//auto_batch: this feature is only available for the PostgreSQL driver(version >= 14.0), see
//the wiki for more details.
"auto_batch": false
//connect_options: extra options for the connection. Only works for PostgreSQL now.
//For more information, see https://www.postgresql.org/docs/16/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
//"connect_options": { "statement_timeout": "1s" }
}
]
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.