Skip to content

Instantly share code, notes, and snippets.

@wprudencio
Last active December 14, 2016 21:28
Show Gist options
  • Save wprudencio/156a89c252a7326bebcae6bf0abf54f3 to your computer and use it in GitHub Desktop.
Save wprudencio/156a89c252a7326bebcae6bf0abf54f3 to your computer and use it in GitHub Desktop.
node_modules/.bin/sequelize db:migrate
node_modules/.bin/sequelize model:create --name Todo --attributes "title:string, complete:boolean,UserId:integer"
-------------
https://github.com/hokaccha/node-jwt-simple
https://jwt.io/introduction/
https://blog.jscrambler.com/implementing-jwt-using-passport/
https://github.com/themikenicholson/passport-jwt
http://stackoverflow.com/questions/17397052/nodejs-passport-authentication-token?noredirect=1&lq=1
http://stackoverflow.com/questions/20228572/passport-local-with-node-jwt-simple
http://mherman.org/
Ajudar com o modelo
https://github.com/scotch-io/easy-node-authentication/blob/facebook/app/models/user.js
https://github.com/yhnavein/express-starter/blob/master/models/sequelize/User.js
-------------
'use strict';
module.exports = function (sequelize, DataTypes) {
var user = sequelize.define('user', {
facebookId: DataTypes.STRING,
email: DataTypes.STRING,
}, {
classMethods: {
associate: function (models) {
// associations can be defined here
}
}
});
return user;
};
----------
var express = require('express');
var models = require(__base + 'models')
module.exports.postSignup = function (req, res) {
var data = {facebookId: 'Hello'}
models.user.findAll().then(function (data) {
console.log(data);
});
// models.user.create(data);
res.json('Que legal');
};
--------------
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
facebookId: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable('users');
}
};
------------------
module.exports = {
up: function (queryInterface, Sequelize) {
queryInterface.addColumn('users', 'email', {
type: Sequelize.STRING,
});
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('users', 'email');
}
};
// ########################################
/* MacBooks-MacBook-Pro:yzzer-api-dev weslei$ node_modules/.bin/sequelize help:model:create
Sequelize [Node: 6.6.0, CLI: 2.5.1, ORM: 3.27.0, pg: ^6.1.2]
Loaded configuration file "config/config.json".
Using environment "development".
COMMANDS
sequelize model:create -- Generates a model and its migration.
sequelize model:generate -- Generates a model and its migration.
DESCRIPTION
This task generates a model file and its respective migration.
It is necessary to specify the name of the new model as well as
the model's attributes.
The attributes can be specified as in the following (and semantically equal) examples:
sequelize model:create --name User --attributes first_name:string,last_name:string,bio:text
sequelize model:create --name User --attributes 'first_name:string last_name:string bio:text'
sequelize model:create --name User --attributes 'first_name:string, last_name:string, bio:text'
This command will generate a new migration and model definition:
// the model file
// located under models/user.js
'use strict';
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
bio: DataTypes.TEXT
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return User;
};
// the migration file
// located under migrations/20161214212742-create-user.js
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
last_name: {
type: Sequelize.STRING
},
bio: {
type: Sequelize.TEXT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable('Users');
}
};
OPTIONS
--env The environment to run the command in. Default: development
--coffee Enables coffee script support. Default: false
--config The path to the config file. Default: config/config.json
--options-path The path to a JSON file with additional options. Default: none
--migrations-path The path to the migrations folder. Default: migrations
--seeders-path The path to the seeders folder. Default: seeders
--models-path The path to the models folder.Default: models
--url The database connection string to use. Alternative to using --config files. Default: none
--name The name of the new model.
--attributes A list of attributes.
--underscored Set timestamps to snake_case
MacBooks-MacBook-Pro:yzzer-api-dev weslei$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment