2
0
Fork 0
tcrud/example/lib/pg-pagila.js

34 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2017-12-23 21:45:27 +00:00
const { Pool } = require('pg');
2017-06-10 14:53:29 +00:00
var pgDBNamed = require('node-postgres-named');
module.exports = {
load: load,
setup: setup
};
function load(tcrud) {
2017-12-23 21:45:27 +00:00
const pool = new Pool({connectionString: 'postgres://postgres:postgresql@localhost/pagila'});
2017-06-10 14:53:29 +00:00
// Create backend with id and uri
2017-12-23 21:45:27 +00:00
tcrud.backend.database.loadPostgres('pg/pagila',pool,pgDBNamed);
2017-06-10 14:53:29 +00:00
}
function setup(tcrud,tcrudModel) {
// Create tcrud models
var tc = tcrud.config;
var t = tc.createTEntityNode(tcrudModel,'pagila');
t.tmeta.tmodel.tbackend = 'pg/pagila';
// Define model and columns
var tLanguage = tc.createTEntity(t,'language','language_id');
var tLanguageId = tc.createTField(tLanguage,'language_id');
var tLanguageName = tc.createTField(tLanguage,'name');
var tLanguageLastUpdate = tc.createTField(tLanguage,'last_update');
var tCountry = tc.createTEntity(t,'country','country_id');
var tCountryId = tc.createTField(tCountry,'country_id');
var tCountryCountry = tc.createTField(tCountry,'country');
var tCountryLastUpdate = tc.createTField(tCountry,'last_update');
}