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(),
* 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.
Rename "model" to "base_model", extend it with "postgre.model"
and "mysql.model" classes. Methods "create" and "update"
are implemented in descendant classes only.
Test "model_spec" was updated. Currently it changes config
of Lapis so that postgres is used.