mysql: lua-resty-mysql backend, models support, fix luasql backend, implement entity_exists #250
Support for models:
All the changes were tested with my project kodomoquiz, which now supports mysql.
model_spec.moon fails now because it requires
I think we should probably create a model base class and and have the postgres and mysql versions extend from it.
This way model spec can be updated to require the specific implementation of the model.
Method cur:fetch of luasql-mysql returns a table, which values are strings, according to . Numbers and boolean variables can be converted to Lua, which was done by this commit. Information about names and types of columns is provided by methods cur:getcolnames() and cur:getcoltypes(), see #46 : https://keplerproject.github.io/luasql/doc/us/manual.html#cur_fetch
* modules "lapis.db" and "lapis.db.schema" select postgres or mysql based on the site's config * method Model.create did rely on RETURNING keyword to get ID of new rows. MySQL has no RETURNING keyword. I used a quick workaround: - if ID is already known (it is not autoincrement field), than variable "values" doesn't need any changing nothing needs to be changed in variable "values". - otherwise, ID is considered to be autoincrement field. The new row ID is provides by both mysql backends: luasql provides res.last_auto_id and lua-resty-mysql provides res.insert_id. Both of them are checked and used as value for the key @primary_key on success. This trick breaks code isolation between models and backends, so it needs some refactoring. All the changes were tested with my project kodomoquiz , which now supports mysql. see #46 : https://github.com/starius/kodomoquiz
Thank you for fixing travis! Current build is failing.
There are three test folders,
Sorry for the delay. It's merged now. I went through a made some refactors and pulled in the model specs from postgres into
There was a bug with composite primary keys messing up autogen ids that I fixed.
I still haven't had a chance to get tests hitting the
Thanks for the patch!