का उपयोग कर एक पीजी टेबल में यूयूआईडी सरणी के साथ रिकॉर्ड कैसे सम्मिलित करें, मुझे अपने डीबी में एक टेबल रखना होगा जिसमें एक कॉलम है जो यूयूआईडी ऑब्जेक्ट्स (यूयूआईडी [] टाइप) की एक सरणी हैनोडजेस पीजी-वादा लाइब्रेरी
लेकिन स्नातकोत्तर-वादा यह विफल
मैं निम्न त्रुटि संदेश मुझे बता पाने जब मैं एक NodeJS पुस्तकालय नामित का उपयोग कर इसे में डालने के लिए कोशिश मैं डाली या
{"name":"error","length":206,"severity":"ERROR","code":"42804","hint":"You will need to rewrite or cast the expression.","position":"230","file":"src\\backend\\parse
r\\parse_target.c","line":"510","routine":"transformAssignedExpr"}
इस अभिव्यक्ति को फिर से लिखने की जरूरत है अजीब है के बाद से मैं बिल्कुल कोई मुद्दे हैं जब मैं एक ही सटीक मेज पर एक और स्तंभ के लिए एक एकल UUID में प्रवेश करने की कोशिश (जिसका अर्थ है, मैं UUID का प्रतिनिधित्व करने के साथ कोई समस्या आती है, btw मैं उन्हें एक lib से एक पाठ चर के रूप में बनाने के लिए, लेकिन वे सादे पुराने पाठ चर हैं)
और न ही मुझे एक समस्या है जब मैं एक ही कॉलम पर टेक्स्ट ऑब्जेक्ट्स की सरणी दर्ज करने का प्रयास करता हूं (यदि मैं तालिका को UUID [] कॉलम के बजाय टेक्स्ट [] कॉलम रखने के लिए बदलता हूं)
यहां मेरा कोड है
////////////////
var Promise = require('bluebird');
var pgpLib = require('pg-promise');
var pgp = pgpLib();
var cn = confUtil.pgDbConnectionConfiguration();
var db = pgp(cn);
//////////////////
var newEntity={};
newEntity.hash = uuid.v4();
newEntity.location = {X:2394876,Y:2342342};
newEntity.mother = uuid.v4();
newEntity.timestamp = Date.now();
newEntity.content = {content:"blah"};
newEntity.sobList = [uuid.v4(),uuid.v4(),uuid.v4()];
addEntity (newEntity);
////////////////////
function addEntity(newEntity) {
var insertEntityQueryPrefix='insert into entities (';
var insertEntityQueryMiddle=') values (';
var insertEntityQueryPostfix="";
var insertEntityQuery="";
Object.keys(newEntity).forEach(function(key){
insertEntityQueryPrefix=insertEntityQueryPrefix+'"'+key+'",';
insertEntityQueryPostfix=insertEntityQueryPostfix+'${'+key+'},';
});
insertEntityQueryPrefix=insertEntityQueryPrefix.slice(0,-1);
insertEntityQueryPostfix=insertEntityQueryPostfix.slice(0,-1)+")";
insertEntityQuery=insertEntityQueryPrefix+insertEntityQueryMiddle+insertEntityQueryPostfix;
//longStoryShort this is how the query template i used looked like
/*
"insert into entities ("hash","location","mother","timestamp","content","sobList") values (${hash},${location},${mother},${timestamp},${content},${sobList})"
*/
//and this is the parameters object i fed to the query i ran it when it failed
/*
{
"hash": "912f6d85-8b47-4d44-98a2-0bbef3727bbd",
"location": {
"X": 2394876,
"Y": 2342342
},
"mother": "87312241-3781-4d7c-bf0b-2159fb6f7f74",
"timestamp": 1440760511354,
"content": {
"content": "bla"
},
"sobList": [
"6f2417e1-b2a0-4e21-8f1d-31e64dea6358",
"417ade4b-d438-4565-abd3-a546713be194",
"e4681d92-0c67-4bdf-973f-2c6a900a5fe4"
]
}
*/
return db.tx(function() {
var processedInsertEntityQuery = this.any(insertEntityQuery,newEntity);
return Promise.all([processedInsertEntityQuery])
})
.then(
function (data) {
return newEntity;
},
function (reason) {
throw new Error(reason);
});
}
बहुत बहुत शुक्रिया विटाली:
एक सरणी के अंदर UUID-एस का उपयोग कर के अपने उदाहरण के लिए, आप अपने खुद के UUID प्रकार लागू कर सकते हैं। यह बिल्कुल मुद्दा था। मुझे एक भावना थी कि आक्रमण था, लेकिन यह नहीं पता था कि कास्टिंग को वाक्यबद्ध तरीके से कैसे जोड़ा जाए। – Tal
अब मैं इसके बारे में लगता है कि। आप एक ही जीवनशैली हैं जिन्होंने पीजी-वादा लिखा था, है ना? अच्छा, अच्छा काम !!! :) अद्भुत lib (हालांकि के रूप में आपने देखा, मैं सिर्फ इसे का उपयोग शुरू कर दिया है, और ज्यादातर गलत तरीके से), लेकिन lib से पूरे वादा समर्थन सीधे महान है। – Tal
हाँ, कि मुझे इस परियोजना की वेबसाइट पर सवाल पूछने के लिए स्वतंत्र लग रहा है :) है: [पीजी वादा] (https://github.com/vitaly-t/pg-promise) का उपयोग करने का –