coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.73k stars 240 forks source link

Add error callback to list() on DbQueryCollection in store.sql as sql might fail #131

Open miklschmidt opened 10 years ago

miklschmidt commented 10 years ago

All the sql stores has error callbacks in their executeSql methods, but the list() method in store.sql doesn't use them. So when a query fails, you'll never know.

I ran into this issue while using the migration plugin, i accidentally created a table with the plural version of the entity's name, and didn't get any callbacks while using the list() function after doing Entity.all().

I added support for error callbacks in .list() on DbQueryCollection, to fix this issue.

AndreaSpinelli commented 10 years ago

I support the issue, because .list(/) and .count() do fail! (see below for an example)

However, IMHO, a better solution would be just to use the same callback on line 711 of persistence.store.sql.js:

      }, callback );

by the way, se same applies to .count() and again a simple fix is changing line 844 to

      }, callback );

This is consistent with the general convention of persistence.js that callbacks should test their second argument; if it is not-null, it is a SQL error.

A simple index.html for testing:

Test