On 02/01/2017 10:34 AM, Suliman wrote:
On Wednesday, 1 February 2017 at 14:06:39 UTC, Suliman wrote:
Am I right understand that Connection instance should created at
constructor and be one single for all class (and it will be reused by
fibers) or am I wrong?

If yes, where I should to close it? To put
scope(exit) c.close();

In destructor?

If yes, does it behavior should be same as for working in vibed pool
and without?

I'm not sure I understand the question here.

Whether you should use a vibed connection pool or not is completely up to you and your program. And the choice of when to create the connection, and when to close the connection, is also up to your own program's needs.

If you're using a connection pool, you shouldn't need to worry about closing the connection. The whole point is that the connections stay open until you need to use one again. When your program ends, then connections will close by themselves.


If I right understand class MysqlDB do not throw any exceptions, So I
can't understand how to handle wrong connection.

if(connection is null)
{
     try // useless
     {
         connection = mydb.lockConnection();
     }
     catch(Exception e)
     {
         writeln(e.msg);
     }
}

mydb.lockConnection() does create a new connection if it needs to. And that WILL throw an exception if there's a problem connecting to the DB server. So your code above WILL catch an exception if the connection information (server address/port/login/etc) is wrong.

Side note: That reminds me, I need to rename the MysqlDB class (and the mysql.db module). It's a connection pool (using vibe-d's connection pool), but their names make that very unclear.


Reply via email to