mirror of
/repos/Prototyper.git
synced 2025-12-30 06:31:32 +01:00
allow for different PK between databases
This commit is contained in:
parent
c43359c69e
commit
7b71cd1bde
16
lib/data.js
16
lib/data.js
@ -66,12 +66,12 @@ module.exports = function (config, dataBase, updateShare) {
|
||||
};
|
||||
if (result.hasOwnProperty(options.attribute) &&
|
||||
result[options.attribute].guid) {
|
||||
attribute_options.query = {
|
||||
id: result[options.attribute].guid
|
||||
};
|
||||
attribute_options.query = {};
|
||||
attribute_options.query[config.database.pk] = result[options.attribute].guid;
|
||||
|
||||
} else {
|
||||
attribute_options.query = {
|
||||
parent: result.id,
|
||||
parent: result[config.database.pk],
|
||||
name: result.name + '.' + options.attribute
|
||||
};
|
||||
|
||||
@ -85,16 +85,16 @@ module.exports = function (config, dataBase, updateShare) {
|
||||
}
|
||||
var updateContent = true;
|
||||
if (result[options.attribute]) {
|
||||
if (attribute_result.id === String(result[options.attribute].guid)) {
|
||||
if (attribute_result[config.database.pk] === String(result[options.attribute].guid)) {
|
||||
updateContent = false;
|
||||
} else {
|
||||
result[options.attribute].guid = attribute_result.id;
|
||||
result[options.attribute].guid = attribute_result[config.database.pk];
|
||||
}
|
||||
} else {
|
||||
result[options.attribute] = {guid: attribute_result.id};
|
||||
result[options.attribute] = {guid: attribute_result[config.database.pk]};
|
||||
}
|
||||
|
||||
attribute_result.parent = result.id;
|
||||
attribute_result.parent = result[config.database.pk];
|
||||
attribute_result.name = result.name + '.' + options.attribute;
|
||||
attribute_result[options.attribute] = data;
|
||||
if (options.operation) {
|
||||
|
||||
@ -57,7 +57,8 @@ module.exports = function (config, mongoInstance, helpers, markers) {
|
||||
config.error && config.error('ERR importer.importer ensureContent', err);
|
||||
return cb && cb(err);
|
||||
}
|
||||
leftover.replacement.query = {id: parent_result.id};
|
||||
leftover.replacement.query = {};
|
||||
leftover.replacement.query[config.database.pk] = parent_result[config.database.pk];
|
||||
|
||||
remainder = remainder.replace(leftover.regExp, '');
|
||||
return mongoInstance.setMongoAttribute(remainder, leftover.replacement, function savedAttribute(err) {
|
||||
@ -103,8 +104,8 @@ module.exports = function (config, mongoInstance, helpers, markers) {
|
||||
config.error && config.error('ERR importer.replaceMarkers JSON.parse(remainder)', remainder, error);
|
||||
return callback && callback(error);
|
||||
}
|
||||
if (data.id) {
|
||||
delete data.id;
|
||||
if (data[config.database.pk]) {
|
||||
delete data[config.database.pk];
|
||||
}
|
||||
_.extend(parent_result, data);
|
||||
context.update = true;
|
||||
@ -120,7 +121,8 @@ module.exports = function (config, mongoInstance, helpers, markers) {
|
||||
});
|
||||
});
|
||||
}
|
||||
context.query = {id: parent_result.id};
|
||||
context.query = {};
|
||||
context.query[config.database.pk] = parent_result[config.database.pk];
|
||||
return mongoInstance.setMongoAttribute(remainder, context, function savedAttribute(err) {
|
||||
if (err) {
|
||||
config.error && config.error('ERR2 importer.importer setMongoAttribute', err);
|
||||
|
||||
@ -4,6 +4,9 @@ var _ = require('underscore');
|
||||
|
||||
|
||||
module.exports = function (config, db) {
|
||||
|
||||
// config.database.pk = '_id'
|
||||
|
||||
/*
|
||||
* options:
|
||||
* collection (mandatory)
|
||||
|
||||
@ -157,8 +157,10 @@ module.exports = function (config, mongoDataInstance, helpers, markers) {
|
||||
var attribute_context = {
|
||||
collection: context.collection,
|
||||
attribute: key,
|
||||
query: {id: context_result.id}
|
||||
query: {}
|
||||
};
|
||||
attribute_context.query[config.database.pk] = context_result[config.database.pk];
|
||||
|
||||
return mongoDataInstance.getMongoAttribute(attribute_context, function cacheTemplateKey(err, template_key_result) {
|
||||
if (err) {
|
||||
config.error && config.error('ERR handlebar.registerHelper getMongoAttribute', err);
|
||||
@ -180,7 +182,8 @@ module.exports = function (config, mongoDataInstance, helpers, markers) {
|
||||
return callback && callback(err);
|
||||
}
|
||||
config.debug && config.debug('// handle markers on rendered template');
|
||||
context.query = {id: context_result.id};
|
||||
context.query = {};
|
||||
context.query[config.database.pk] = context_result[config.database.pk];
|
||||
return getPreviewHTML(rendered, context, function handlePreviewResult(err, preview_html) {
|
||||
if (err) {
|
||||
config.error && config.error('ERR template_tag getPreviewHTML', err);
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
var _ = require('underscore');
|
||||
|
||||
module.exports = function (config, r, connection) {
|
||||
|
||||
// config.database.pk = 'id'
|
||||
|
||||
/*
|
||||
* options:
|
||||
* collection (mandatory)
|
||||
|
||||
@ -14,8 +14,9 @@ module.exports = function (app, handlers, markers, config) {
|
||||
collection: req.params.collection,
|
||||
attribute: req.params.attribute,
|
||||
ext: req.params.ext,
|
||||
query: {id: req.params.guid}
|
||||
query: {}
|
||||
};
|
||||
options.query[config.database.pk] = req.params.guid;
|
||||
handlers.getAttribute(options,
|
||||
responder(config, options, res, next)
|
||||
);
|
||||
@ -29,8 +30,9 @@ module.exports = function (app, handlers, markers, config) {
|
||||
var options = {
|
||||
collection: req.params.collection,
|
||||
ext: req.params.ext,
|
||||
query: {id: req.params.guid}
|
||||
query: {}
|
||||
};
|
||||
options.query[config.database.pk] = req.params.guid;
|
||||
handlers.getContent(options,
|
||||
responder(config, options, res, next)
|
||||
);
|
||||
@ -103,9 +105,10 @@ module.exports = function (app, handlers, markers, config) {
|
||||
collection: options.collection,
|
||||
name: options.name,
|
||||
attribute: attribute,
|
||||
query: {id: result.id},
|
||||
query: {},
|
||||
req: options.req
|
||||
};
|
||||
options.query[config.database.pk] = result[config.database.pk];
|
||||
|
||||
config.debug && config.debug('getPreviewContent content', attribute_value);
|
||||
handlers.getPreviewHTML(attribute_value,
|
||||
|
||||
@ -71,7 +71,6 @@ module.exports = function (config, model, mongoDataInstance) {
|
||||
attribute: null
|
||||
};
|
||||
if (splitId.length === 4) {
|
||||
// options.query = {_id: splitId[2]};
|
||||
options.query = {name: splitId[2]};
|
||||
options.attribute = splitId[3];
|
||||
mongoDataInstance.getMongoAttribute(options, handleMongoGetResult(options));
|
||||
@ -185,7 +184,6 @@ module.exports = function (config, model, mongoDataInstance) {
|
||||
};
|
||||
var attribute = false;
|
||||
if (splitId.length === 4) {
|
||||
// options.query = {_id: splitId[2]};
|
||||
options.query = {name: splitId[2]};
|
||||
options.attribute = splitId[3];
|
||||
attribute = true;
|
||||
|
||||
@ -75,7 +75,7 @@ module.exports = function (config, shareModel) {
|
||||
});
|
||||
} else if (doc.type.name === 'json') {
|
||||
_.forEach(keys, function (key) {
|
||||
if (key !== 'id') {
|
||||
if (key !== config.database.pk) {
|
||||
var op = {
|
||||
p: [key]
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user