-
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.
Starting to get the data setup in a new database using an ORM
- Loading branch information
Showing
10 changed files
with
193 additions
and
18 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
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
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
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 = function (sequelize, DataTypes) { | ||
var Entry = sequelize.define('Entry', { | ||
lemma: { type: DataTypes.STRING, allowNull: false }, | ||
ipa: { type: DataTypes.STRING, allowNull: false }, | ||
partOfSpeech: { type: DataTypes.STRING, allowNull: false }, | ||
odd: { type: DataTypes.STRING }, | ||
audio: { type: DataTypes.STRING } | ||
}); | ||
|
||
Entry.associate = function (models) { | ||
// associations can be defined here | ||
Entry.hasMany(models.LocalizedEntry); | ||
Entry.belongsTo(models.Source); | ||
}; | ||
|
||
return Entry; | ||
}; |
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,35 @@ | ||
"use strict"; | ||
|
||
var fs = require("fs"); | ||
var path = require("path"); | ||
var Sequelize = require("sequelize"); | ||
var env = process.env.NODE_ENV || "development"; | ||
var vault = require('../vault'); | ||
|
||
if (process.env.DATABASE_URL) { | ||
var sequelize = new Sequelize(process.env.DATABASE_URL,vault[env].ln_dictionary); | ||
} else { | ||
var sequelize = new Sequelize(vault[env].ln_dictionary.database, vault[env].ln_dictionary.username, vault[env].ln_dictionary.password, vault[env].ln_dictionary); | ||
} | ||
var db = {}; | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter(function(file) { | ||
return (file.indexOf(".") !== 0) && (file !== "index.js"); | ||
}) | ||
.forEach(function(file) { | ||
var model = sequelize.import(path.join(__dirname, file)); | ||
db[model.name] = model; | ||
}); | ||
|
||
Object.keys(db).forEach(function(modelName) { | ||
if ("associate" in db[modelName]) { | ||
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,16 @@ | ||
'use strict'; | ||
module.exports = function (sequelize, DataTypes) { | ||
var LocalizedEntry = sequelize.define('LocalizedEntry', { | ||
lc: { type: DataTypes.STRING, allowNull: false }, | ||
test: DataTypes.INTEGER | ||
}, { | ||
classMethods: { | ||
associate: function (models) { | ||
// associations can be defined here | ||
console.log("This is being called..."); | ||
LocalizedEntry.belongsTo(models.Entry); | ||
} | ||
} | ||
}); | ||
return LocalizedEntry; | ||
}; |
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,14 @@ | ||
'use strict'; | ||
module.exports = function (sequelize, DataTypes) { | ||
var Source = sequelize.define('Source', { | ||
name: { type: DataTypes.STRING, unique: true }, | ||
description: DataTypes.STRING | ||
}); | ||
|
||
Source.associate = function (models) { | ||
// associations can be defined here | ||
Source.hasMany(models.Entry); | ||
}; | ||
|
||
return Source; | ||
}; |
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
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