One bad thing when you work with sails js is do all the models by hand... until now, this generator helps to do this task in a very simple way.
The usage of this generator is a bite simple, you must clone this repo in your sails project, and run:
#git clone https://github.com/cadrogui/sails-generator-automodel.git automodel
#cd automodel
Link AutoModel
#sudo npm link
and finally on your sails project root folder, you can use AutoModel
#sails generate automodel
Automodel will find all conections that use sails-mysql adapter, and will prompt for usage.... and thats all, automodel will generate all files for represent you database.
Automodel support all data types present in waterline:
- string
- text
- integer
- float
- date
- time
- datetime
- boolean
- binary
- array
- json
At this version AutoModel can detect all foreign keys only as model attribute, if in your associations you need the virtual attribute collections you must create by your self, but half way is taken by AutoModel, in the next releases i will try to give the power to AutoModel to handle complete associations.
module.exports = {
"identity": "Pets",
"connection": "sails_test",
"autoCreatedAt": false,
"autoUpdatedAt": false,
"attributes": {
"id": {
"type": "INTEGER",
"primaryKey": "TRUE",
"autoIncrement": "TRUE"
},
"name": "STRING",
"Owners": {
"model": "Owners",
"columnName": "owner_id"
}
}
}
module.exports = {
"identity": "Owners",
"connection": "sails_test",
"autoCreatedAt": false,
"autoUpdatedAt": false,
"attributes": {
"id": {
"type": "INTEGER",
"primaryKey": "TRUE",
"autoIncrement": "TRUE"
},
"name": "STRING",
"lastname": "STRING",
"email": "STRING"
}
}
As you can see automodel helps a lot with the tedious task of creating the models.
Maybe use js templates for models, now all do programmaticallyEmebed all code in sails generator- Package the generator as npm
- Implement more efficient ways to detect relations between models
I hope AutoModel helps to make all of your models as an easy task, as well for me.