C2FO / patio

Idiomatic database toolkit

Home Page:http://c2fo.github.io/patio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default value detection

mbenedettini opened this issue · comments

Hello:

I had a problem with patio detecting a column's default value, specifically with timestamp type and CURRENT_TIMESTAMP default value.

This is my table definition:

mysql> desc clients;
+----------+--------------+------+-----+-------------------+-----------------------------+
| Field    | Type         | Null | Key | Default           | Extra                       |
+----------+--------------+------+-----+-------------------+-----------------------------+
| id       | int(11)      | NO   | PRI | NULL              | auto_increment              |
| name     | varchar(255) | NO   |     | John              |                             |
| lastName | varchar(255) | NO   |     | NULL              |                             |
| created  | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| updated  | datetime     | YES  |     | NULL              |                             |
+----------+--------------+------+-----+-------------------+-----------------------------+
5 rows in set (0.00 sec)

And this is the error I was getting

TypeError: Object CURRENT_TIMESTAMP has no method 'match'
[2012-08-01T14:02:07:641 (ART)] ERROR                      - TypeError: Object CURRENT_TIMESTAMP has no method 'match'
at define.instance.__columnSchemaToJsDefault (/home/mariano/work/dingo/node_modules/patio/lib/database/query.js:752:95)
at defaultFunction (/home/mariano/work/dingo/node_modules/comb/lib/define.js:36:26)
at wrapper [as __columnSchemaToJsDefault] (/home/mariano/work/dingo/node_modules/comb/lib/define.js:49:17)
at define.instance.schema.schemaParseTable.then.hitch.schemas.(anonymous function) (/home/mariano/work/dingo/node_modules/patio/lib/database/query.js:304:48)
at Array.forEach (native)
at define.instance.schema (/home/mariano/work/dingo/node_modules/patio/lib/database/query.js:301:30)
[...]

First of all, I'm quite new to patio so I'm not sure if I'm doing something wrong. However, I could track the problem down to Database.__columnSchemaToJsDefault(def, type). The argument def (column's default value) is supposed to be a string but instead a buffer was being passed.
So I wrote a small patch to treat the column's default value in a similar way to the column's type: https://gist.github.com/3228630

I repeat: I'm new to patio, so any advice is appreciated.
Thanks,
Mariano.

Hi, so the fix is in master I have not republished yet to npm as I have a few other features that are going into the next release. Feel free to clone or fork and link the module to get the fixed code!

git clone git@github.com:Pollenware/patio.git
cd ./patio && npm link

Then in your project

npm link patio

Enjoy!

-Doug

Awesome, thanks a lot!