Commit 6f6a81f5 authored by Mark Stenglein's avatar Mark Stenglein

Start working with the models

- not sure on data organization just yet, but it should be set to
  actually _have_ models added as needed/wanted
parent d327f8a8
# Schedules
*By Mason SRCT*
## Models Directory
This directory stores the different models used by the application.
module.exports = function(sequelize, DataTypes) {
var Section = sequelize.define("Section", {
// unique index/key
crn : DataTypes.STRING,
name : DataTypes.STRING,
title : DataTypes.STRING,
section : DataTypes.STRING,
// should be foreign key
instructor : DataTypes.STRING,
// should be foreign key
campus : DataTypes.STRING,
// should be foreign key
location : DataTypes.STRING,
// should be foreign key
class_type : DataTypes.STRING,
// Start Time Information
startDate : DataTypes.DATE,
endDate : DataTypes.DATE,
Msession : DataTypes.BOOL,
MtimeStart : DataTypes.TIME,
MtimeEnd : DataTypes.TIME,
Tsession : DataTypes.BOOL,
TtimeStart : DataTypes.TIME,
TtimeEnd : DataTypes.TIME,
Wsession : DataTypes.BOOL,
WtimeStart : DataTypes.TIME,
WtimeEnd : DataTypes.TIME,
Rsession : DataTypes.BOOL,
RtimeStart : DataTypes.TIME,
RtimeEnd : DataTypes.TIME,
Fsession : DataTypes.BOOL,
FtimeStart : DataTypes.TIME,
FtimeEnd : DataTypes.TIME
})
}
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var config = require('config');
// get configuration for sequelize
// worth noting that this changes depending on the environment
var sequelizeConf = config.get('sequelize');
// make the new connection
var sequelize = new Sequelize(sequelizeConf);
// empty variable to load entire database into
var db = {};
// this section load every model file in the `models` dir into the database
fs
.readdirSync(__dirname)
.flter(function(file) {
return (file.indexOf("." !== 0)) && (file !== "index.js");
})
.forEach(function(file) {
var model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});
// TODO: figure out exactly what this is doing
Object.keys(db).forEach(function(modelName) {
if ("associate" in db[modelName]) {
db[modelName].associate(db);
}
})
// add the configs and module to the `db` object
db.sequelize = sequelize;
db.Sequelize = Sequelize;
// return the finished database object to the calling module
module.exports = db;
......@@ -18,7 +18,8 @@
"node-sass": "^3.8.0",
"node-sass-middleware": "0.8.0",
"pug": "^2.0.0-beta6",
"sequelize": "^3.24.6"
"sequelize": "^3.24.6",
"sqlite3": "^3.1.8"
},
"devDependencies": {
"chai": "^3.5.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment