2
0
Fork 0
tcrud/example/lib/pg-pagila.js
2017-12-23 22:45:27 +01:00

34 lines
1.1 KiB
JavaScript

const { Pool } = require('pg');
var pgDBNamed = require('node-postgres-named');
module.exports = {
load: load,
setup: setup
};
function load(tcrud) {
const pool = new Pool({connectionString: 'postgres://postgres:postgresql@localhost/pagila'});
// Create backend with id and uri
tcrud.backend.database.loadPostgres('pg/pagila',pool,pgDBNamed);
}
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');
}