Question about store data
-
wrote on 21 Apr 2025, 13:44 last edited by
Hello, I have a question, I am implementing a single tone class for connecting to databases, the main task is to place the database in a pool when connecting, I use the PIMPL approach to store data, but here is the question, if a smart pointer is used, then it cannot be copied and placed in a pool, and in principle the logic is broken, it seems to me, what is the best way to implement this?
DbConnection.h
Class DbConnection{
private:
DbConnection() = default;
struct Data;
std::unique_ptr<Data> pData;
//other code
public:
QList<std::unique_ptr<Data>> poolConnections;
bool connect();
//
}DbConnection.cpp
struct DbConnection::Data{
QString host;
QString port;
//other
}bool connect(){
….
how to add each new connection to pool?
} -
Hello, I have a question, I am implementing a single tone class for connecting to databases, the main task is to place the database in a pool when connecting, I use the PIMPL approach to store data, but here is the question, if a smart pointer is used, then it cannot be copied and placed in a pool, and in principle the logic is broken, it seems to me, what is the best way to implement this?
DbConnection.h
Class DbConnection{
private:
DbConnection() = default;
struct Data;
std::unique_ptr<Data> pData;
//other code
public:
QList<std::unique_ptr<Data>> poolConnections;
bool connect();
//
}DbConnection.cpp
struct DbConnection::Data{
QString host;
QString port;
//other
}bool connect(){
….
how to add each new connection to pool?
}wrote on 21 Apr 2025, 14:13 last edited byHi, your design seems a bit unusual but the easiest way is to store one instance/smart pointer of something like
ConnectionData
in your singleton (instead of a list). And inConnectionData
you store a list of your actual connection data. -
Hi, your design seems a bit unusual but the easiest way is to store one instance/smart pointer of something like
ConnectionData
in your singleton (instead of a list). And inConnectionData
you store a list of your actual connection data.wrote on 21 Apr 2025, 18:46 last edited by@Pl45m4 honestly, I haven't decided how best to implement it, I thought maybe there was another alternative? I didn't fully understand what you meant, just store in the auxiliary structure not the data but the list of connections?
2/3