drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.52k stars 1.1k forks source link

getDbClient always returns nullptr (postgresql) #826

Closed nodeverror closed 3 years ago

nodeverror commented 3 years ago

When trying to use getDbClient in controller method the pointer returned is always null. My configuration file is loaded, the database is running and I can connect to it via DBeaver fine using the same connection information below. I get no error from drogon, just a nullptr.

-- Found PostgreSQL: /usr/lib/libpq.so (found version "13.2")  
-- pg inc: /usr/include/usr/include/postgresql/server
-- Found pg: /usr/lib/libpq.so  
 "db_clients": [
        {
            "name":"default",
            "rdbms": "postgresql",
            "host": "localhost",
            "port": 5432,
            "dbname": "postgres",
            "user": "postgres",
            "passwd": "",
            "is_fast": false,
            "number_of_connections": 1
        }
void User::getInfo(const HttpRequestPtr &req, std::function<void (const HttpResponsePtr &)> &&callback)
{
...
    auto dbClient = drogon::app().getDbClient();
    assert(dbClient);
...
}
an-tao commented 3 years ago

Please run drogon_ctl -v to check if the libpq is linked against into drogon.

nodeverror commented 3 years ago

Please run drogon_ctl -v to check if the libpq is linked against into drogon.

Here is the output:

A utility for drogon
Version: 1.5.1
Git commit: 87d812327687b29dd6e685bb5106638dd4aba969
Compilation: 
  Compiler: /usr/bin/c++
  Compiler ID: GNU
  Compilation flags: -O3 -DNDEBUG -std=c++17 -I/usr/include
Libraries: 
  postgresql: yes  (batch mode: no)
  mariadb: yes
  sqlite3: yes
  openssl: yes
  brotli: yes
  boost: no
  hiredis: yes
  c-ares: yes
an-tao commented 3 years ago

please paste the whole config.json file, may be the configuration of database is commented (it is commented by default when the configuration file is generated by drogon_ctl).

nodeverror commented 3 years ago

please paste the whole config.json file, may be the configuration of database is commented (it is commented by default when the configuration file is generated by drogon_ctl).

I am so sorry! I completely missed that the section was commented out. My bad, all is well now.