我正在使用sequelize-auto
來從我的數據庫生成數據類型,它工作得很好。結果是這樣的:如何使用Node.js從Sequelize數據類型創建Breeze元數據?
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'
});
};
現在我試圖設置Breeze服務器,它需要元數據。這些示例從json
文件中提取元數據,但我想從我的模型中構建元數據。我怎樣才能做到這一點?
這是從例子(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);
}
目前[MetadataMapper(https://開頭github.com/Breeze/breeze.server.node/blob/master/breeze-sequelize/src/MetadataMapper.js)只能從[Breeze元數據](http://breeze.github.io/doc- js/metadata-schema.html#metadata-example)到Sequelize。如果有一種工具可以採用另一種方式,尤其是使用'sequelize-auto'時,那將是非常好的。 –
嗨史蒂夫,感謝您的評論...我實際上黑了一個工具去其他方式,並得到它的工作...非常醜陋,不支持大多數數據類型,但現在爲我工作 –