forked from asishallab/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Get started tutorial
edwards33 edited this page Sep 14, 2017
·
4 revisions
- Open ScienceDbBackend project/folder and run following (Note: examples represent how to create taxon Data-Model which has 3 attributes: name, taxonomic_level, parent_id):
./node_modules/.bin/sequelize model:create --name taxon --attributes 'name:string, taxonomic_level:string, parent_id:integer'
cd /server/models
Currently the model have to be modified manually (see examples bellow).
- automatically generated model:
'use strict';
module.exports = function(sequelize, DataTypes) {
var taxon = sequelize.define('taxon', {
name: DataTypes.STRING,
taxonomic_level: DataTypes.STRING,
parent_id: DataTypes.INTEGER
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return taxon;
};
- and modified model (Note: you can edit it on your host or into docker container using vim ):
'use strict';
module.exports = function(sequelize, DataTypes) {
var taxon = sequelize.define('taxon', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
name: {
type: DataTypes.STRING,
allowNull: false
},
taxonomic_level: {
type: DataTypes.STRING,
allowNull: false
},
parent_id: DataTypes.INTEGER
}, {
classMethods: {
associate: function(models) {
taxon.belongsTo(models.taxon, {foreignKey: 'parent_id', targetKey: 'id'})
}
}
});
return taxon;
};
- Run the migration to create the tables:
./node_modules/.bin/sequelize db:migrate
- Create routes/controller:
express_route_gen . --name taxon --attributes 'name:string, taxonomic_level:string, parent_id:integer'
- Generate GUI. Run command in admin_gui_gen:
admin_gui_gen . --baseUrl http://localhost:3000 --name taxon --attributes 'name:string, taxonomic_level:string' --belongsTo 'taxon:parent_id:id:name:taxonomic_level'
- Edit index.js file (which is located in ScienceDbGui/router folder)
- add following objects into routes array:
{
path: '/taxons',
name: 'taxons',
component: taxons,
},
{
path: '/taxon/:id',
name: 'taxonEdit',
component: taxonEdit,
},
{
path: '/taxon',
name: 'taxonCreate',
component: taxonCreate,
}
Note: don't forget to import appropriate components
import taxons from '@/components/taxons'
import taxonCreate from '@/components/taxonCreateForm'
import taxonEdit from '@/components/taxonEditForm'
- Prepoulate taxons with some data:
curl 'http://localhost:3000/taxons' -X POST --data 'name=test_1&taxonomic_level=level_1'