/Praise_Server

๐Ÿ’›Server๋กœ ์ฐธ์—ฌํ•œ ์†์ปคํ†ค ํ”„๋กœ์ ํŠธ๐Ÿฌ

Primary LanguageJavaScript

๐Ÿ’™ ์„œ๋น„์Šค ํ•œ์ค„ ์†Œ๊ฐœ ๐Ÿ’™

  • ๊ทธ๊ฑฐ ์•Œ์•„? ์นญ์ฐฌ์€ ํ•˜๋ฉด ํ• ์ˆ˜๋ก ๊ธฐ๋ถ„์ด ์ข‹์•„์ง„๋‹ค๋Š”๊ฑฐ? ์šฐ๋ฆฌ ๋ชจ๋‘ ์นญ์ฐฌ ์ค‘๋…์ด ๋˜์–ด๋ณด๋Š”๊ฑฐ ์–ด๋•Œ~?


โœ” ๊ณ ๋ž˜๋‹จ ์„œ๋ฒ„ ์ปจ๋ฒค์…˜ โœ”


๐Ÿ‹ ์„œ๋น„์Šค ๋ช… ๐Ÿ‹

  • ์นญ์ฐฌํ• ๊ณ ๋ž˜

1


์„œ๋ฒ„ ์•„ํ‚คํ…์ณ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-04-30 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 9 50 26


ERD(Entity Relation Diagram)

ERD


models/index.js

const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require('../config/config.json')[env];
const db = {};

let sequelize;
if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
  sequelize = new Sequelize(config.database, config.username, config.password, config);
}

db.sequelize = sequelize;
db.Sequelize = Sequelize;

db.praise = require('./praise')(sequelize, Sequelize);
db.praiseTarget = require('./praiseTarget')(sequelize, Sequelize);
db.user = require('./user')(sequelize, Sequelize);

/** 1 : 1   Praise : PraiseTarget */
db.praise.hasOne(db.praiseTarget, { onDelete: 'cascade' });
db.praiseTarget.belongsTo(db.praise);

/** 1 : N   User : PraiseTarget */
db.user.hasMany(db.praiseTarget, { ondDelete: 'cascade' });
db.praiseTarget.belongsTo(db.user, { onDelete: 'cascade' });

module.exports = db;


Contributor