2
0
Fork 0
tcrud/example/lib/pg-moviedb.js
2017-06-10 16:53:29 +02:00

61 lines
2.4 KiB
JavaScript

var pgDB = require('pg');
var pgDBNamed = require('node-postgres-named');
module.exports = {
setup: setup,
load: load
};
function load(tcrud) {
// Create backend with id and uri
tcrud.backend.database.loadPostgres('pg/moviedb','postgres://postgres:postgresql@localhost/moviedb',pgDB,pgDBNamed);
}
function setup(tcrud,tcrudModel) {
// Create tcrud models
var tc = tcrud.config;
var t = tc.createTEntityNode(tcrudModel,'moviedb');
t.tmeta.tmodel.tbackend = 'pg/moviedb';
// Define model and columns
var tCompany = tc.createTEntity(t,'company','company_id');
var tCompanyId = tc.createTField(tCompany,'company_id');
var tCompanyName = tc.createTField(tCompany,'name');
var tCompanyDateEst = tc.createTField(tCompany,'date_est');
var tCompanyRemarks = tc.createTField(tCompany,'remarks');
var tCompanyCountryId = tc.createTField(tCompany,'country_id');
var tCountry = tc.createTEntity(t,'country','country_id');
var tCountryCompany = tc.createTEntity(tCountry,'company','company_id');
var tCountryCompanyId = tc.createTField(tCountryCompany,'company_id');
var tCountryCompanyName = tc.createTField(tCountryCompany,'name');
var tCountryCompanyDateEst = tc.createTField(tCountryCompany,'date_est');
var tCountryCompanyRemarks = tc.createTField(tCountryCompany,'remarks');
var tCountryCompanyCountryId = tc.createTField(tCountryCompany,'country_id');
var tCountryId = tc.createTField(tCountry,'country_id');
var tCountryCode = tc.createTField(tCountry,'code');
var tCountryName = tc.createTField(tCountry,'name');
var tDirector = tc.createTEntity(t,'director','director_id');
var tDirectorId = tc.createTField(tDirector,'director_id');
var tDirectorDateBorn = tc.createTField(tDirector,'date_born');
var tDirectorDateDied = tc.createTField(tDirector,'date_died');
var tDirectorFirstName = tc.createTField(tDirector,'first_name');
var tDirectorLastName = tc.createTField(tDirector,'last_name');
var tGenre = tc.createTEntity(t,'genre','genre_id');
var tGenreId = tc.createTField(tGenre,'genre_id');
var tGenreCode = tc.createTField(tGenre,'code');
var tGenreName = tc.createTField(tGenre,'name');
tCompany.tmeta.tmenu.ticon='fa fa-building';
//tCountryCompany.tmeta.tmenu.ticon='fa fa-building';
tCountry.tmeta.tmenu.ticon='fa fa-globe';
tDirector.tmeta.tmenu.ticon='fa fa-cogs';
tGenre.tmeta.tmenu.ticon='fa fa-star';
}