WIP open file for a while
This commit is contained in:
parent
f937019e42
commit
d280fb9af3
122 changed files with 5702 additions and 10 deletions
26
example/lib/ldapjs-example.js
Normal file
26
example/lib/ldapjs-example.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
var ldap = require('ldapjs');
|
||||
|
||||
module.exports = {
|
||||
setup: setup
|
||||
};
|
||||
|
||||
function setup(tcrud,tcrudModel) {
|
||||
|
||||
var client = ldap.createClient({
|
||||
url: 'ldap://127.0.0.1:389'
|
||||
});
|
||||
|
||||
// Create backend with id and uri
|
||||
tcrud.plugin.backend.ldapjs.registrate('ldapjs/main',client);
|
||||
|
||||
// Create tcrud models
|
||||
var tc = tcrud.config;
|
||||
var t = tc.createTEntityNode(tcrudModel,'ldapjs');
|
||||
t.tmeta.tmodel.tbackend = 'ldapjs/main';
|
||||
|
||||
// Define model and columns
|
||||
var tUser = tc.createTEntity(t,'cn=foo, o=example','cn');
|
||||
var tUserId = tc.createTField(tUser,'uid');
|
||||
var tUserName = tc.createTField(tUser,'sn');
|
||||
var tUserEmail = tc.createTField(tUser,'email');
|
||||
}
|
||||
153
example/lib/mongoose-blog.js
Normal file
153
example/lib/mongoose-blog.js
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
var mongoose = require('mongoose');
|
||||
var log = require('winston').loggers.get('main');
|
||||
var tcrud = require('../../lib/node-ff-tcrud');
|
||||
|
||||
module.exports = {
|
||||
setup: setup
|
||||
};
|
||||
|
||||
function setup(tcrud,tcrudModel) {
|
||||
|
||||
var mongoUrl = 'mongodb://localhost:27017/blog';
|
||||
var mongoOptions = {
|
||||
db: {
|
||||
fsync: false,
|
||||
journal: false,
|
||||
native_parser: true,
|
||||
forceServerObjectId: true
|
||||
},
|
||||
server: {
|
||||
poolSize: 4,
|
||||
socketOptions: {
|
||||
connectTimeoutMS: 500,
|
||||
keepAlive: 1,
|
||||
auto_reconnect: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
log.info('Connecting to: ' + mongoUrl);
|
||||
var conn = mongoose.createConnection(mongoUrl,mongoOptions);
|
||||
|
||||
tcrud.plugin.backend.mongoose.registrate('mongoose/blog',conn);
|
||||
conn.model('blog-state', modelSchemaBlogState, 'blog_state');
|
||||
|
||||
var tc = tcrud.config;
|
||||
var crudAdmin = tc.createTEntityNode(tcrudModel,'admin');
|
||||
crudAdmin.troles.push('admin');
|
||||
|
||||
var crudAdminModels = tcrud.plugin.backend.mongoose.buildTEntityModels(conn,crudAdmin);
|
||||
log.info('crud admin models created: '+crudAdminModels.length);
|
||||
crudAdminModels.forEach(function(model) {
|
||||
model.tmeta.tmodel.tbackend = 'mongoose/blog';
|
||||
});
|
||||
}
|
||||
|
||||
var modelMetaBlogState = {
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
index: { unique: true },
|
||||
tfield: {
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
trim: true,
|
||||
index: { unique: false },
|
||||
tfield: {
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
trim: true,
|
||||
tfield: {
|
||||
xtype: 'textarea',
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
trim: true,
|
||||
tfield: {
|
||||
ttype: 'textarea',
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
changed_date: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
tfield: {
|
||||
tlist: { tenable: false },
|
||||
},
|
||||
},
|
||||
created_date: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
tfield: {
|
||||
tlist: { tenable: false },
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
var modelSchemaBlogState = new mongoose.Schema(modelMetaBlogState);
|
||||
modelSchemaBlogState.statics = tcrud.plugin.backend.mongoose.buildStaticsModelValidated(modelMetaBlogState,modelSchemaBlogState, {
|
||||
findLastChangedLimit5: function (callback) {
|
||||
log.debug(modelBackend+'.findLastChangedLimit5');
|
||||
this.find({}).sort('-changed_date').limit(5).exec(callback);
|
||||
},
|
||||
findOneByName: function (name, callback) {
|
||||
log.debug(modelBackend+'.findByName name='+name);
|
||||
this.findOne({name:name}).exec(callback);
|
||||
},
|
||||
ensureExcists: function (name, type, defaultValue, description, callback) {
|
||||
this.findOneByName(name, function(err, xprop) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (xprop == null) {
|
||||
log.debug(modelBackend+'.getByName create name='+name+' defaultValue='+defaultValue);
|
||||
var model = mongoose.model('blog-state');
|
||||
xprop = new model();
|
||||
xprop.name = name;
|
||||
xprop.type = type;
|
||||
xprop.value = defaultValue;
|
||||
xprop.description = description;
|
||||
xprop.save(function(err,xprop) {
|
||||
if (callback) {
|
||||
callback(err, xprop);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.debug(modelBackend+'.getByName fetched name='+name);
|
||||
if (callback) {
|
||||
callback(null, xprop);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
setByName: function (name, value, callback) {
|
||||
this.findOneByName(name, function(err, xprop) {
|
||||
if (err) { throw err }
|
||||
log.debug(modelBackend+'.setByName name='+name+' valueNew='+value+' valueOld='+xprop.value);
|
||||
xprop.value = value;
|
||||
xprop.save(function(err) {
|
||||
callback(err, xprop);
|
||||
});
|
||||
});
|
||||
},
|
||||
incByName: function (name, callback) {
|
||||
this.findOneByName(name, function(err, xprop) {
|
||||
if (err) { throw err }
|
||||
xprop.value++;
|
||||
log.debug(modelBackend+'.incByName name='+name+' value='+xprop.value);
|
||||
xprop.save(function(err) {
|
||||
callback(err, xprop);
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
60
example/lib/pg-moviedb.js
Normal file
60
example/lib/pg-moviedb.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
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';
|
||||
}
|
||||
31
example/lib/pg-pagila.js
Normal file
31
example/lib/pg-pagila.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
var pgDB = require('pg');
|
||||
var pgDBNamed = require('node-postgres-named');
|
||||
|
||||
module.exports = {
|
||||
load: load,
|
||||
setup: setup
|
||||
};
|
||||
|
||||
function load(tcrud) {
|
||||
// Create backend with id and uri
|
||||
tcrud.backend.database.loadPostgres('pg/pagila','postgres://postgres:postgresql@localhost/pagila',pgDB,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');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue