Skip to content

Instantly share code, notes, and snippets.

@unicodeveloper
Created August 18, 2017 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unicodeveloper/a5f96ade0e0ee75140fa3870eea49ae7 to your computer and use it in GitHub Desktop.
Save unicodeveloper/a5f96ade0e0ee75140fa3870eea49ae7 to your computer and use it in GitHub Desktop.
import Sequelize from ‘sequelize’;
import env from ‘node-env-file’;
env(‘.env’);
/*
 Create instance of DB Connection.
 We will be using JawsDB PostgreSQL resource from https://manifold.co
*/
const db = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
 host: process.env.DB_HOST,
 dialect: ‘postgres’,
});
// Import our models we created
const UserModel = db.import(‘../models/user’);
const NoteModel = db.import(‘../models/note’);
// Specify the relationships between our models
NoteModel.belongsTo(UserModel);
UserModel.hasMany(NoteModel);
const Note = db.models.notes;
const User = db.models.users;
export { Note, User };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment