I have a written specification for a sizable database that will be hosted in postgresql and used as a datasource for a backloop nodejs api implementation.
The problem is the specification is written in no way parsable by a machine directly so i will have to create the models and the structure myself.
I have only recently started working with loopback and i have mostly used django before. From what i saw i think the method that fits me is dataSource.createModel
but that method does not create the json
files in the common/model
folder so its not really going to work for the api.
Is there a way to build the models both in the database and the api registry? this is my code so far :(
var path = require('path');
var app = require(path.resolve(__dirname, '../server'));
// var ds = require('../data-sources/db')('oracle');
var ds = app.dataSources.floatDB;
var User = ds.createModel('User', {
email: { type: String, limit: 150, index: true },
password: { type: String, limit: 50 },
birthDate: Date,
registrationDate: {type: Date, default: function () { return new Date }},
activated: { type: Boolean, default: false }
});
ds.automigrate(function () {
ds.discoverModelProperties('CUSTOMER_TEST', function (err, props) {
console.log(props);
});
});
PS my models will have foreign keys and relationships like this
{
"name": "Order",
"base": "PersistedModel",
"properties": {
"description": {
"type": "string"
},
"total": {
"type": "number"
}
},
"validations": [],
"relations": {
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": ""
}
},
"acls": [],
"methods": []
}