framework can not find dbclient

7 Relevant Page: Database-dbclient
glebs 6 months ago

From main: ..... findConfigFile(configFile); // my function


    // get database client ptr
    auto dptr = app().getFastDbClient("postgresql_client");


From config.json: ],
"db_clients": [ { "name": "postgresql_client", // rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default "rdbms": "postgresql", "filename":"", "host": "", "port": 5432, "dbname": "some_db", "user": "some_user", "passwd": "some_password", "is_fast": true, "client_encoding": "", // connection_number: 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.
"connection_number": 1 } ],

Program builds successfully, framework was built with postgres support.


./dosgate-web 20200906 21:25:58.634049 UTC 1483193 DEBUG [findConfigFile] Using /tmp/dosgate-web/config.json configuration file - dosgate-web: /home/gleb/src/inteldom/drogon/lib/src/DbClientManager.h:42: drogon::orm::DbClientPtr drogon::orm::DbClientManager::getFastDbClient(const string&): Assertion `iter != dbFastClientsMap_.end()' failed.

What's happened and how to debug?

antao2002 6 months ago

Users should run the getFastDbClient after running app().run(), usually we call this method in a handler for Http requests, that's no problem. if you want to do something in the main function, you could get it as follows:

    app().registerBeginningAdvice([]() {
       //Here the current thread is main event loop thread, and it's valid for fast database client, so we could get it here.
       auto dptr = app().getFastDbClient("postgresql_client");
       *aptr << "select ...." ...;
glebs 6 months ago

No, I do not nee the access to the database from main. So I found that for the 'non-fast' db client the rule is the same, One need to get the pointer to db client after running app().run(). In this case I have a question: what is the right way to obtain the reference to framework from a controller' class method?

glebs 5 months ago

Thank you. The code works but only if I name the db client as "default" in config file. If I name the db client in some other way , the "my_client" for example, and call the app().getFastDbClient("my_client") function, result will be the same. The framework crashes on assertion.

antao2002 5 months ago

I'll check this.

antao2002 5 months ago

Hi, I can't reproduce the issuse if I named the client to "my_client" and use getFastDbClient("my_client"), it works fine (I check it on Linux and MacOS). Please check whether the client in config file is named to "my_client" and whether the 'is_fast' option is true.

glebs 5 months ago , edited 5 months ago

OK. Sorry, You are right. named client is found successfully. It was temporary lapse of reason. I wrote test to double check this.

Log in to comment