I am using sequelize-auto to generate data types from my database and it works great. The result is something like this:
module.exports = function(sequelize, DataTypes) {
return sequelize.define('ReportTasks', {
ReportTaskID: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
BatchID: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'ReportBatches',
key: 'BatchID'
}
},
Name: {
type: DataTypes.STRING,
allowNull: true
},
Year: {
type: DataTypes.INTEGER,
allowNull: true
},
Month: {
type: DataTypes.INTEGER,
allowNull: true
},
CompanyKey: {
type: DataTypes.INTEGER,
allowNull: true
},
CompanyName: {
type: DataTypes.STRING,
allowNull: true
},
StartDate: {
type: DataTypes.DATE,
allowNull: true
},
EndDate: {
type: DataTypes.DATE,
allowNull: true
},
Status: {
type: DataTypes.STRING,
allowNull: true
}
}, {
tableName: 'ReportTasks'
});
};
Now I am trying to setup Breeze server and it needs metadata. The examples pull the metadata from a json file, but I want to build the metadata from my models. How can I achieve this?
This is the code from the example (http://breeze.github.io/doc-node-sequelize/introduction.html):
function createSequelizeManager() {
var metadata = readMetadata();
var sm = new SequelizeManager(dbConfig, sequelizeOptions);
sm.importMetadata(metadata);
return sm;
}
function readMetadata() {
var filename = "TodoMetadata.json";
if (!fs.existsSync(filename)) {
throw new Error("Unable to locate file: " + filename);
}
var metadata = fs.readFileSync(filename, 'utf8');
return JSON.parse(metadata);
}
via Brandon Johnson
No comments:
Post a Comment