korma/Korma — pull request #107 by tyano (2013-01-07 12:11:16+00:00)
Title: A patch for COUNT() function on MySQL

This is a patch for COUNT() function on MySQL.

Korma generate a SQL from a query with (aggregate (count :*) :cnt) on MySQL as bellow:

(select users (aggregate (count :*) :cnt))

to

SELECT COUNT(`users`.*) `cnt` FROM `users`

But this SQL doesn't work on MySQL, because an argument of COUNT() must be a simple '*' instead of `users`.* if the argument is '*'.

Yes, it is a dialect of MySQL. But I think it is a big issue that very usual sql-function COUNT(*) doesn't work on currently-most-famous-sql-database-in-the-world with Korma.

In my patche, I changed a korma.sql.fns/agg-count function to multimethod. It works in the same manner as before if the subprotocol of a database of a query isn't mysql. but if the subprotocol is 'mysql', it works for mysql and generate a SQL as bellow:

SELECT COUNT(*) `cnt` FROM `users`

See korma.test.core.clj.

And this patch will solve Issue #81 well.