February 01, 2017
Plz update dub package on code.dlang.org
February 01, 2017
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?
February 01, 2017
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?

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);
	}
}
February 01, 2017
Also I can't understand what is SQL Command and what exec is doing if it's returning ulong?


February 01, 2017
On 02/01/2017 05:04 AM, Suliman wrote:
> Plz update dub package on code.dlang.org

It's deliberately not in the main mysql-mative package just yet. I will put it there once people have a chance to try this, and it becomes clear there aren't any big problems with the redesign.

For now, this preview can be used like this:

$ git clone https://github.com/Abscissa/mysql-native-experimental.git
$ dub add-local mysql-native-experimental

And then, when you're doing using this preview:

$ dub remove-local mysql-native-experimental

February 01, 2017
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.


February 01, 2017
On 02/01/2017 01:54 PM, Suliman wrote:
> Also I can't understand what is SQL Command and what exec is doing if
> it's returning ulong?
>
>

"struct Command" should not be used. It is old, and a bad design. This new release attempts to replace it with a better design. Hopefully, "struct Command" will be deleted in a later release.

The "exec" functions are for commands like INSERT, UPDATE, DELETE, CREATE, etc (it is *not* for SELECT). It is for things that do NOT return actual rows of data. The "exec" functions return "rows affected" - the number of rows that were affected by your INSERT, or UPDATE, etc. Usually people ignore that number, but it's information the server sends back, and is sometimes useful to some people. For example, SQL administration tools usually tell you "# rows affected" after you run an INSERT/UPDATE/etc.

If you are doing a SELECT, then you do NOT use "exec", you use "query" for SELECT. "query" returns a set of rows.

Summary:
---------

SELECT: Use query() or querySet() or queryRow(), etc.

INSERT/UPDATE/DELETE/CREATE/DROP: Use exec(). Return value tells you how many rows were added/changed/deleted/etc.

February 02, 2017
Made a couple more long-needed changes while I'm at it:

https://github.com/Abscissa/mysql-native-experimental
Tag: v0.2.0-preview2

- For better clarity, renamed `mysql.db.MysqlDB` to `mysql.pool.MySqlPool`.

- Package mysql.connection no longer acts as a package.d, publicly importing other modules. To import all of mysql-native, use `import mysql;`

February 02, 2017
On Thursday, 2 February 2017 at 05:28:10 UTC, Nick Sabalausky wrote:
> Made a couple more long-needed changes while I'm at it:
>
> https://github.com/Abscissa/mysql-native-experimental
> Tag: v0.2.0-preview2
>
> - For better clarity, renamed `mysql.db.MysqlDB` to `mysql.pool.MySqlPool`.
>
> - Package mysql.connection no longer acts as a package.d, publicly importing other modules. To import all of mysql-native, use `import mysql;`

Thanks! Could you explain about pool. I googled about it, and still can't understand when it up new connections?

How can I imagine what connection is? Because without it hard to understand what difference between connections with and without pool.

Am I right understand that if I use pool I can create connection instance one time in DB class constructor end every new connection will be created on demand?
February 02, 2017
On Thursday, 2 February 2017 at 06:50:34 UTC, Suliman wrote:
> On Thursday, 2 February 2017 at 05:28:10 UTC, Nick Sabalausky wrote:
>> Made a couple more long-needed changes while I'm at it:
>>
>> https://github.com/Abscissa/mysql-native-experimental
>> Tag: v0.2.0-preview2
>>
>> - For better clarity, renamed `mysql.db.MysqlDB` to `mysql.pool.MySqlPool`.
>>
>> - Package mysql.connection no longer acts as a package.d, publicly importing other modules. To import all of mysql-native, use `import mysql;`
>
> Thanks! Could you explain about pool. I googled about it, and still can't understand when it up new connections?
>
> How can I imagine what connection is? Because without it hard to understand what difference between connections with and without pool.
>
> Am I right understand that if I use pool I can create connection instance one time in DB class constructor end every new connection will be created on demand?

Ok, I read articles about pool, as I understood it's depend on of the implementation. For example method `close` in pool mode should not close connection, but return it to pool.

Could you tell about your implementation. Also actual question is can I open connection in constructor (during class instance creation) ?