forked from sequelize/express-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renamed express-main-example orchestra and added blog example project
- Loading branch information
Showing
51 changed files
with
806 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
|
||
# Created by https://www.toptal.com/developers/gitignore/api/node,macos | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=node,macos | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
.env*.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/node,macos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Blog: Sequelize + Express | ||
|
||
This is an example of how to setup Sequelize and Express together in a project for NodeJS 10 and above. | ||
|
||
Feel free to download this and use as a starting point for your new project! | ||
|
||
This example uses PostgreSQL as a database engine. | ||
|
||
## See it in action | ||
|
||
* Install PostgreSQL and run `$ createdb sequelize-blog` | ||
* Install project dependencies with `npm install` or `yarn install` | ||
* Run the migrations `$ sequelize db:migrate` | ||
* Run the express server with `npm start` | ||
* Open your browser in `localhost:3000` and explore. Review the `routes` files to see what endpoints are available. | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"development": { | ||
"username": "adambraus", | ||
"password": null, | ||
"database": "sequelize-blog", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"test": { | ||
"username": "root", | ||
"password": null, | ||
"database": "sequelize-blog-test", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"production": { | ||
"use_env_variable": "DATABASE_URL" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (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 | ||
}, | ||
email: { | ||
type: Sequelize.STRING | ||
}, | ||
bio: { | ||
type: Sequelize.TEXT | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Users'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Posts', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
title: { | ||
type: Sequelize.STRING | ||
}, | ||
body: { | ||
type: Sequelize.TEXT | ||
}, | ||
UserId: { | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Posts'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Comments', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
body: { | ||
type: Sequelize.TEXT | ||
}, | ||
PostId: { | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Comments'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('Users', 'dob', { type: Sequelize.DATE }); | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.removeColumn('Users', 'dob'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('Users', 'password', { type: Sequelize.STRING }); | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.removeColumn('Users', 'password'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const Comment = sequelize.define('Comment', { | ||
body: DataTypes.TEXT, | ||
PostId: DataTypes.INTEGER | ||
}); | ||
|
||
Comment.associate = function (models) { | ||
Comment.belongsTo(models.Post); | ||
}; | ||
|
||
return Comment; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var Sequelize = require('sequelize'); | ||
var basename = path.basename(__filename); | ||
var env = process.env.NODE_ENV || 'development'; | ||
var config = require(__dirname + '/../config/config.json')[env]; | ||
var db = {}; | ||
|
||
if (config.use_env_variable) { | ||
var sequelize = new Sequelize(process.env[config.use_env_variable]); | ||
} else { | ||
var sequelize = new Sequelize(config.database, config.username, config.password, config); | ||
} | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter(file => { | ||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); | ||
}) | ||
.forEach(file => { | ||
var model = sequelize['import'](path.join(__dirname, file)); | ||
db[model.name] = model; | ||
}); | ||
|
||
Object.keys(db).forEach(modelName => { | ||
if (db[modelName].associate) { | ||
db[modelName].associate(db); | ||
} | ||
}); | ||
|
||
db.sequelize = sequelize; | ||
db.Sequelize = Sequelize; | ||
|
||
module.exports = db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const Post = sequelize.define('Post', { | ||
title: DataTypes.STRING, | ||
body: DataTypes.TEXT, | ||
UserId: DataTypes.INTEGER | ||
}) | ||
|
||
Post.associate = function (models) { | ||
Post.belongsTo(models.User); | ||
Post.hasMany(models.Comment); | ||
|
||
// Publication.belongsToMany(models.Post, { through: 'Publication_Post' }); | ||
// Post.belongsToMany(models.Publication, { through: 'Publication_Post' }); | ||
}; | ||
|
||
return Post; | ||
}; |
Oops, something went wrong.